简体   繁体   English

SMTP的窗口API

[英]window api for smtps

is there any windows api that can send mail using smtp along with attachment . 是否有任何Windows API可以使用smtp 和附件发送邮件。 I have heard its not possible,and i have to use other socket methods,if its true how can I do that?? 我听说这是不可能的,我必须使用其他套接字方法,如果确实如此,我该怎么做?

please suggest c++ or c solution only,no c# or java(like system.net.mail etc) 请仅建议使用C ++或C解决方案,不建议使用C#或Java(例如system.net.mail等)

This is one of those places that (at least in my experience) you're better off without libraries. 这是(至少以我的经验)最好没有图书馆的地方之一。 Microsoft provides (at least) MAPI, Simple MAPI, and CDO as ways of sending email. Microsoft提供(至少)MAPI,Simple MAPI和CDO作为发送电子邮件的方式。 Unfortunately, at least in my experience all of them ( especially MAPI) are considerably more complex than doing the job on your own. 不幸的是,至少以我的经验,所有这些方法( 尤其是 MAPI)都比自己完成工作复杂得多。

At least as long as you're dealing with an unsecured email connection, doing the job without a library is pretty simple: connect to the server on port 25. Send it a few strings and the email. 至少在处理不安全的电子邮件连接时,没有库就很简单:在端口25上连接到服务器。向它发送一些字符串和电子邮件。 When you get down to it, the "Simple" is "Simple Mail Transfer Protocol" is completely warranted -- it really is pretty simple to do. 当您开始使用它时,“简单”就是“简单邮件传输协议”是完全必要的-确实非常简单。

If you want to do a secure connection you'll almost certainly want to use a library for that though -- creating a secure connection is a decidedly non-trivial task. 如果要建立安全连接,则几乎可以肯定要为此使用一个库-创建安全连接绝对不是一件容易的事。 Since you're using Windows, the obvious choice would be InternetOpen and InternetConnect . 由于您使用的是Windows,因此显而易见的选择是InternetOpenInternetConnect Contrary to the documentation, InternetConnect will let you create a connection on almost any port. 与文档相反, InternetConnect将使您可以在几乎任何端口上创建连接。 It only lists a half dozen possibilities or so, but if you just pass an actual port number, such as 465 or 587, that should work -- though there are a few ports WinInet blocks as a (probably ineffective) security measure. 它仅列出了大约五种可能性,但是,如果您仅传递一个实际的端口号(例如465或587),则应该可以使用-尽管有一些端口是WinInet阻止的(可能是无效的)安全措施。

Dealing with an attachment is a (mostly) separate question. 处理附件是(大多数)单独的问题。 An attachment simply ends up as text in the body of the email, with enough of a header to tell the receiving email program to interpret it as an attachment instead of text. 附件只是以电子邮件正文中的文本结尾,带有足够的标头来告诉接收电子邮件的程序将其解释为附件而不是文本。 There are three reasonably popular possibilities: BinHex, UUencode, and MIME. 存在三种相当流行的可能性:BinHex,UUencode和MIME。 If you just want to do simple attachments, UUencode is probably the way to go. 如果您只是想做简单的附件,UUencode可能是您要走的路。 MIME is more capable, but considerably more complex. MIME更强大,但复杂得多。 The main reason to use it would be if you wanted to do things other than simple attachments (eg, email with files embedded rather than attached). 使用它的主要原因是您是否想做一些简单的附件以外的事情(例如,带有嵌入式文件而不是附件的电子邮件)。 BinHex is marginally simpler to implement, but wastes more space -- the primary reason to use it is for a few ancient email clients that can't handle anything else. BinHex的实现稍微简单一些,但浪费更多的空间-使用它的主要原因是一些古老的电子邮件客户端无法处理其他任何事情。

Here's a link to a wxWidget smtp class . 这是wxWidget smtp类的链接。 If you take a look at it, you should get an idea of how to send an email message. 如果您看一看,应该对如何发送电子邮件有所了解。

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

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