views:

275

answers:

2

is it possible to do it without any third-party lib.

i can send mail to gmail with a simple socket functions. i can send files one computer to another too. But i need to send with attachment to any mail account...

can it be done with smtp?

(i searched in here but the answers, that i looked, are not in c++ or not on windows or not open source completely. Sorry if there is/are answer(s) that given before, but i couldn't find )

thanks,

+2  A: 

Absolutely yes.

As far as SMTP is concerned, you just provide it with the appropriate headers (the rfc822 is out of date, but is a good start) and then the message body, which can be anything.

You probably want to create a message body that is a MIME encoded message describing the text of the email and any attachments.

The question you should be asking is:

How do I construct a MIME encoded email message that I can send to SMTP?

Also, the problem of creating email messages and sending them has been solved so many times, you should really consider using a library if you're at all able to.

John Weldon
"How do I construct a MIME encoded email message that I can send to SMTP?"Yes that is the true question...
H2O
+2  A: 

The MIME parts were answered succinctly in the closed question http://stackoverflow.com/questions/2210023/how-do-i-attach-a-file-in-an-email-message-generated-by-a-c-program.

The SMTP parts you'll find in other related answers such as http://stackoverflow.com/questions/1966073/how-do-i-send-attachments-using-smtp

Liudvikas Bukys
in the first link, there is nothing that show me how to use MIME in c++?And second link, solutions are in pyhton. Actually i can send mails. But smtp doesn't support attachment. anyway...thanks for the reply...
H2O
You'll have to do something OS-specific to get your mail into the hands of a mail transfer agent (MTA): Open a TCP socket to an SMTP server. [Socket API is not OS-provided, not part of C++.] Or open a pipe to, say, sendmail or qmail. [Pipe API such as popen() is OS-provided, not part of C++.]
Liudvikas Bukys