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

发布于 2024-08-11 01:19:49 字数 4000 浏览 2 评论 0原文

注意:如果您没有时间阅读这个漫长的旅程,解决方案(带有源代码)在这里:http:// www.coastrd.com/smtps

长期以来,通过远程邮件服务器(通常在网站托管公司)使用 SMTP(端口 25)发送电子邮件很容易通过应用程序完成。打开 TCP 端口 25,发送“HELO ...”等

使用 google 电子邮件服务执行此操作给我带来了问题,因为他们坚持使用端口 465 SMTPS,即带有 TLS 加密的 SMTP:

http://en.wikipedia.org/wiki/Transport_Layer_Security#How_it_works

在研究使用 C++ 等语言或基本的味道,我遇到:

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

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

和一个 Python 问题:

python smtp gmail身份验证错误(通过gmail smtp服务器发送电子邮件)

如果我理解正确的话,我将需要在我的 C++ 代码中实现 TLS 加密,完成所有握手和协商?

来自 C# 问题:

使用 gmail smtp (安全层)发送电子邮件在 C++ 中

这个库不这样做

http://johnwiggins.net/jwsmtp/

<强>添加:

很多人只是将 stunnel 安装为服务,然后将其配置为管理 SSL 连接

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

Stunnel 是一个 OpenSSL 包装器。 OpenSSL 有一些性能问题 (http://josefsson.org/gnutls4win/)

“初始化 libgcrypt 需要很长时间在某些系统上,有报告称这可能需要大约 10 秒。”

并需要:“libeay32.dll”1.35MB +“libssl32.dll”310k +“zlib1.dll”75k

然后有一些商业产品:

http://www.chilkatsoft.com/downloads.asp

该产品主要作为 Activex (COM)“dll”提供(需要用户计算机上的安装程序才能“注册 dll - 另一个糟糕的 .net 想法)。

安装程序加载“ChilkatMime.dll”1.33Mb、“ChilkatCert.dll”1.26MB、“ChilkatUtil.dll”720k。开发人员对在真正的 C .dll 库上进行合作根本不感兴趣,该库可以从任何语言(包括 C/C++/BASIC/Python 等)调用。考虑到他们的态度,我对他们成为代码生成器的受害者并不感到惊讶。由黑客。

除了俗气的名字和艺术品之外,他们的产品价格也很合理,但我尝试过的产品,尽管被告知要使用端口 465,却连接在端口 25 上。

相比之下,催化剂的商业选项:

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

现在作为主要套筒工具产品的组件提供,价格仅为其 1/3。这些工具是一流的!是的,一分钱一分货。开发人员积极响应并乐于接受建议。他们提供所有类型的 dll,包括一个独立的 .dll,它可以随您的产品一起提供,只有 230k!对于商业解决方案,他们轻而易举地获胜。

SLL/TLS 连接可以显式地(握手开始后)或隐式地(在使用 STARTTLS 等握手之后)

例如,CodeIgniter 是隐式的(Python、asp、php 等中的选项也是如此) http://codeigniter.com/forums/viewthread/84689/

连接成功后一旦完成,就存在一个“隧道”,MIME 会话可以通过该“隧道”进行:

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

带有来自服务器的通常响应。

某些语言会为您处理 MIME 通信(套接字工具、codeigniter 等),您只需输入电子邮件主题、正文和地址,即可轻松使用

CryptLib 是一种开源解决方案,可通过 C 语言实现 SSL/TLS 隧道style .dll 仅 1MB(完整编译)。由于源代码可用,因此可以仅使用您需要的组件来编译 dll 的版本,但其数量应该稍微少一些。

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

尽管我让库立即运行并询问 MIME 对话框,但作者的反应非常积极。有330页的说明书!谢谢。

该库不是 MTA(邮件传输代理),因此您必须在上面编写 MIME 对话,但它是免费的!

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

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: " + "[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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

夕色琉璃 2024-08-18 01:19:49

查看 http://sourceforge.net/projects/libquickmail/
该库可以将带有可选附件的邮件发送给多个收件人。
SMTP 传输依赖于 libcurl,因此它支持身份验证和 TLS 等功能。
C API 使用起来非常简单。
在 Linux (GCC) 和 Windows (MinGW) 上进行了测试,但应该适用于任何可用 libcurl 的平台。

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.

兮颜 2024-08-18 01:19:49

您是正确的,您需要在应用程序中启用 TLS。我建议您不要自己执行此操作,而是查看 OpenSSL

此外,您需要在您的帐户中启用 SMTP 支持 SMTP 身份验证发送流量通过 Gmail。

还有一个重复问题,其中有一些提示以及 C# 实现,其中的代码可能可以帮助您。

还有一个库可能比自己滚动更容易使用(尽管目前还没有TLS 支持)。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文