Click here to Skip to main content
14,979,401 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How can one send HTML Email and mail with attachment in c++.Where can I get sample codes.
Pls I need it for a client/Server Application.
Posted

1 solution

What you want to look for is called an SMTP Client[^]. I have written several for use internally for my company (source not available) but these are fairly common.

One of the issues you will encounter is that mail relays are somewhat locked down these days, and you will likely need to do additional authorization and security steps from what are the likely default settings. If possible, you also want to use SSL and/or TLS options and don't send password info in clear text.
   
Comments
Gbenbam 13-Sep-13 12:01pm
   
None of the search result talked about how to send attachment. i am interested in sending attachments too.
H.Brydon 13-Sep-13 12:19pm
   
I'm not sure what you are looking at. The coding examples don't include attachment examples but every library listed at this Google page supports attachments (MIME or otherwise).
pasztorpisti 15-Sep-13 15:43pm
   
+5, contains all the important info. I would add a few notes of mine if you don't mind. 1-2 years ago I needed a C++ smtp client and I couldn't really find one that is good enough. That time this was maybe the best simple and free solution: http://www.codeproject.com/Articles/98355/SMTP-Client-with-SSL-TLS. It contained some ugly and unsafe sprintfs, it didn't handle well some mime header related rules but it did a fairly good job and supports SSL+passwords. According to the article it supports file attachment but I haven't used it. (Since then I've written my own solution.) To OP: SMTP and sometimes HTTP uses MIME to encode binary data and unicode text into ASCII (because the smtp protocol basically allows sending only ascii characters and a maximum of 80(?) chars per line) and to arrange the sendable mail and data into a tree structure. Read more about it: http://en.wikipedia.org/wiki/MIME: "Through the use of the multipart type, MIME allows mail messages to have parts arranged in a tree structure where the leaf nodes are any non-multipart content type and the non-leaf nodes are any of a variety of multipart types." Of course the tree may contain encoded binary files (for example base64 encoded jpg pictures) and you can reference these nodes from the text of the mail (that is also a node in the tree). So basically MIME is a stupid encoding that allows you to pack together different kind of data items (file data, text/message) with some additional infos (each node can have headers - basically key-value pairs) and finally mime stores this tree in a stupid ascii-text format that has short lines (usually a maximum of 79 chars if I remember right) to allow sending it over stupid old smtp channels. Read more if you are interested about mime and search with google for examples if you are interested. To be honest it isn't an easy topic it it is worth reading the wiki page and maybe an rfc about this widely used encoding and play around a bit with mime. When I learnt mime I used python script interpreter to put together mime trees and I checked out the output of an already working mime encoder. Another confusing thing is that that same content can be encoded in different ways...
H.Brydon 15-Sep-13 16:05pm
   
Thanks - that info is actually solution-worthy by itself.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900