views:

936

answers:

1

For a long time sending email uing SMTP (port 25) via a remote mail server (usually at the website hosting company) was easy to do with an application. Open a TCP port 25, send "HELO ..." etc

To do this using googles email service is giving me a problem because they insist on using port 465 SMTPS ie SMTP with TLS encryption:

http://en.wikipedia.org/wiki/Transport%5FLayer%5FSecurity#How%5Fit%5Fworks

In researching a way to do this with a language like C++ or a flavor of basic, i came across:

http://forums.realsoftware.com/viewtopic.php?f=2&t=29542

http://forums.realsoftware.com/viewtopic.php?f=2&t=26959&p=162671#p162671

and a Python question:

http://stackoverflow.com/questions/1384535/python-smtp-gmail-authentication-error-sending-email-through-gmail-smtp-server

If I am understanding this correctly, I am going to need to implement the TLS encryption in my C++ code, complete with all the hand shaking and negotiation?

From the C# question:

http://stackoverflow.com/questions/1226213/sending-email-with-gmail-smtp-secure-layer-in-c

This library does not do it

http://johnwiggins.net/jwsmtp/

ADDED:

A lot of people are just installing the stunnel as a service and then configuring it to manage the an SSL connection

http://www.stunnel.org/about/

Stunnel is an OpenSSL wrapper. OpenSSL has some perfomance issues (http://josefsson.org/gnutls4win/)

"Initializing libgcrypt takes a long time on some systems, there has been reports that it can take around 10 seconds."

and requires: "libeay32.dll" 1.35MB + "libssl32.dll" 310k + "zlib1.dll" 75k

Then thre are a couple of commercial products:

http://www. c h i l k a t s o f t.com/downloads.asp

This product is mostly delivered as an Activex (COM) "dll" (requiring an installer on the users machine to 'register' the dll - another bad .net idea).

The installer loads "ChilkatMime.dll" 1.33Mb, "ChilkatCert.dll" 1.26MB, "ChilkatUtil.dll" 720k. The developers were not at all interested in cooperating on a true C .dll library that could be called from any language including C/C++/BASIC/Python etc etc. Given their attitude I am not surprised they have been the victim of code generators made by hackers.

Apart from the cheesy name and artwork, their products are reasonably priced, but the one I tried, connected on port 25 despite being told to use port 465.

By contrast, a commercial option from catalyst:

http://www.catalyst.com/products/sockettools/secure/library/index.html

is now available as component of the main socket tools product for 1/3 the price. These tools are first class! yes, you get what you pay for. The developers are responsive and open to suggestions. They offer ALL flavors of dll including a stand alone .dll that can be shipped with you product that is only 230k! For commecial solutions they win hands down.

An SLL/TLS connection can be made explicitly (as soon as the handshake begins the seesion) or implicitly (after the handshake using STARTTLS etc)

CodeIgniter is implicit for example (as are options in Python, asp, php etc) http://codeigniter.com/forums/viewthread/84689/

Once the connection has been made, a "tunnel" exists through which a MIME session may proceed:

  "EHLO " + sLocalHost + CRLF
  "MAIL FROM: " + sMailFrom + CRLF
  "RCPT TO: " + "[email protected]" + CRLF  
  "DATA: Testing, Testing xyz" + CRLF 
  CRLF + "." + CRLF
  "QUIT"

with the usual responses from the server.

Some languages handle the MIME communication for you (socket tools, codeigniter, etc) and you just feed in the email subject, body and address making it very easy to use

CryptLib is an open source solution that facilitates an SSL/TLS tunnel with a C style .dll in only 1MB (full compilation). Since the source is available, it is possible to compile a version of the dll with just the components you need that should come in somewhat less than that.

http://www.cs.auckland.ac.nz/~pgut001/cryptlib/download.html

The author was very responsive even though I got the library to work immediately and was asking about the MIME dialog. There is 330 page manual! Thank you.

THis library is not an MTA (mail transfer agent) so you must write the MIME conversation above, but it is FREE!

source code available here: http://www.coastrd.com/smtps.

+1  A: 

You are correct that you'll need to enable TLS in your application. Instead of doing this on your own, I'd suggest looking into OpenSSL.

Additionally, You need to enable SMTP in your account and support SMTP authentication to send traffic through Gmail.

There is also a duplicate question that has some pointers and a C# implementation with code that might be able to help you out.

There is also a library that might be easier to use than rolling your own (although it doesn't currently have TLS support).

jheddings
ooooh thank you for finding that dupliacte. I will change the question to make it more relevant for C++ and third party libraries.
Mike Trader
the john wiggins library doesn't support encrytion if I read that page correctly.
Mike Trader
@Mike Trader: no, it doesn't have SSL/TLS support yet. Looking at the forums for the project, it looks like "it's coming." Hopefully it will at least give you some pointers for handling SMTP-AUTH. Or, you could dive into it and add it... There's a community that would thank you for it!
jheddings