简体   繁体   English

使用SMTPS(TLS)通过gmail(smtp.gmail.com)发送电子邮件的开源库

[英]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 . 注意:如果您没有时间阅读这段漫长的旅程,那么解决方案(包含源代码)就在这里: 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. 很长一段时间,通过远程邮件服务器(通常在网站托管公司)发送电子邮件到SMTP(端口25)对于应用程序很容易。 Open a TCP port 25, send "HELO ..." etc 打开TCP端口25,发送“HELO ...”等

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: 要使用谷歌电子邮件服务给我一个问题是因为他们坚持使用端口465 SMTPS即使用TLS加密的SMTP:

http://en.wikipedia.org/wiki/Transport_Layer_Security#How_it_works 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: 在研究使用C ++或基本风格这样的语言时,我遇到了:

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

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

and a Python question: 和一个Python问题:

python smtp gmail authentication error (sending email through gmail smtp server) python smtp gmail身份验证错误(通过gmail smtp服务器发送电子邮件)

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? 如果我正确理解这一点,我将需要在我的C ++代码中实现TLS加密,完成所有的握手和协商?

From the C# question: 从C#问题:

sending email with gmail smtp ( secure layer ) in c++ 用c ++发送带有gmail smtp(安全层)的电子邮件

This library does not do it 这个库没有这样做

http://johnwiggins.net/jwsmtp/ 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 很多人只是将stunnel安装为服务,然后将其配置为管理SSL连接

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

Stunnel is an OpenSSL wrapper. Stunnel是一个OpenSSL包装器。 OpenSSL has some perfomance issues ( http://josefsson.org/gnutls4win/ ) OpenSSL有一些性能问题( http://josefsson.org/gnutls4win/

"Initializing libgcrypt takes a long time on some systems, there has been reports that it can take around 10 seconds." “在某些系统上初始化libgcrypt需要很长时间,据报道它可能需要大约10秒钟。”

and requires: "libeay32.dll" 1.35MB + "libssl32.dll" 310k + "zlib1.dll" 75k 并要求:“libeay32.dll”1.35MB +“libssl32.dll”310k +“zlib1.dll”75k

Then thre are a couple of commercial products: 然后是几种商业产品:

http://www.chilkatsoft.com/downloads.asp 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). 该产品主要作为Activex(COM)“dll”提供(需要用户机器上的安装程序“注册”dll - 另一个糟糕的.net想法)。

The installer loads "ChilkatMime.dll" 1.33Mb, "ChilkatCert.dll" 1.26MB, "ChilkatUtil.dll" 720k. 安装程序加载“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. 开发人员根本没有兴趣合作一个真正的C .dll库,可以从任何语言调用,包括C / C ++ / BASIC / Python等。鉴于他们的态度,我并不感到惊讶他们是代码生成器的受害者黑客。

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. 除了俗气的名字和艺术品,他们的产品价格合理,但我试过的,尽管被告知使用端口465连接端口25。

By contrast, a commercial option from catalyst: 相比之下,催化剂的商业选择:

http://www.catalyst.com/products/sockettools/secure/library/index.html 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. 现在可以作为主要套接字工具产品的组件,价格的1/3。 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! 他们提供各种风格的dll,包括一个独立的.dll,可以随身携带只有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) SLL / TLS连接可以显式(一旦握手开始,可以)或隐式(在握手后使用STARTTLS等)

CodeIgniter is implicit for example (as are options in Python, asp, php etc) http://codeigniter.com/forums/viewthread/84689/ CodeIgniter是隐式的(例如Python,asp,php等中的选项) http://codeigniter.com/forums/viewthread/84689/

Once the connection has been made, a "tunnel" exists through which a MIME session may proceed: 建立连接后,就会存在“隧道”,通过该隧道可以继续进行MIME会话:

  "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 有些语言为您处理MIME通信(套接字工具,codeigniter等),您只需输入电子邮件主题,正文和地址,使其易于使用

CryptLib is an open source solution that facilitates an SSL/TLS tunnel with a C style .dll in only 1MB (full compilation). CryptLib是一个开源解决方案,它使用C风格.dll的SSL / TLS隧道只需1MB(完整编译)。 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. 由于源是可用的,因此可以编译一个版本的dll,只需要你需要的组件,这些组件应该比这个要少一些。

http://www.cs.auckland.ac.nz/~pgut001/cryptlib/download.html 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. 即使我让库立即工作并询问MIME对话框,作者也非常敏感。 There is 330 page manual! 手册有330页! Thank you. 谢谢。

THis library is not an MTA (mail transfer agent) so you must write the MIME conversation above, but it is FREE! 这个库不是MTA(邮件传输代理),因此您必须编写上面的MIME对话,但它是免费的!

source code available here: http://www.coastrd.com/smtps . 源代码可在此处获取: http//www.coastrd.com/smtps

Check out http://sourceforge.net/projects/libquickmail/ . 查看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. SMTP传输依赖于libcurl,因此它支持身份验证和TLS等功能。 The C API is very simple to use. C API使用起来非常简单。 Tested on Linux (GCC) and Windows (MinGW) but should work on any platform where libcurl is available. 在Linux(GCC)和Windows(MinGW)上测试,但应该在任何可用libcurl的平台上运行。

You are correct that you'll need to enable TLS in your application. 您是正确的,您需要在您的应用程序中启用TLS。 Instead of doing this on your own, I'd suggest looking into OpenSSL . 我建议你研究一下OpenSSL ,而不是自己动手做。

Additionally, You need to enable SMTP in your account and support SMTP authentication to send traffic through Gmail. 此外,您需要在帐户中启用SMTP 支持SMTP身份验证才能通过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. 还有一个重复的问题有一些指针和一个C#实现 ,代码可以帮助你。

There is also a library that might be easier to use than rolling your own (although it doesn't currently have TLS support). 还有一个库可能比滚动自己更容易使用(尽管它目前没有TLS支持)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM