简体   繁体   中英

window api for smtps

is there any windows api that can send mail using smtp along with attachment . 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)

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. Unfortunately, at least in my experience all of them ( especially MAPI) are considerably more complex than doing the job on your own.

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. 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 . Contrary to the documentation, InternetConnect will let you create a connection on almost any port. 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.

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. If you just want to do simple attachments, UUencode is probably the way to go. MIME is more capable, but considerably more complex. 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.

Here's a link to a wxWidget smtp class . If you take a look at it, you should get an idea of how to send an email message.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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