开发者

Open Source Library for sending emails via gmail (smtp.gmail.com) using SMTPS (TLS)

Note: If you dont have time to read this long journey, the solution (with sourcecode) is here: http://www.coastrd.com/smtps.

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_Layer_Security#How_it_works

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:

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:

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.chilkatsoft.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: " + "me@mydomain.com" + 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.


Check out http://sourceforge.net/projects/libquickmail/ . This library can send mail with optional attachments to multiple recipients. The SMTP transport relies on libcurl, so it supports things like authentication and TLS. The C API is very simple to use. Tested on Linux (GCC) and Windows (MinGW) but should work on any platform where libcurl is available.


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).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜