Skip to main content
GameDev.net gamedev.net
🔒 Locked

Send email via C++ program

Started by The C modest god Feb 20, 2005 at 8:15 AM 11 replies 2.9k views
Original Post
The C modest god
The C modest god
I would like with a click of a button in a dialog box to send an email to a specific email. I would like to do it without using C# only with C++, is it possible? Where should I start?
It's all about the wheel.Never blindly trust technoligy.I love my internal organs.Real men don't shower. Quote: Original post by Toolmaker Quote:
Evil Steve
Evil Steve
In C++, you' use winsock, and ask the user for their ISP's SMTP servers address. For instance mine is smtp.blueyonder.co.uk. You can then connect to that address on port 25 and send SMTP commands to send the E-Mail. Here's an example transaction (Lines sent by the app are prefixed with "> ", and lines sent by the server are prefixed with "< "):
< 220 SMTP server ready> HELO Jazzy mail sender program< 250 Hello Jazzy mail sender program [64.26.15.112]> MAIL FROM:<MyName@MyServer.com>< 250 Ok, Sender accepted> RCPT TO:<Target@TargetHost.com>< 250, Ok, That is a valid mailbox> DATA< 354 Send data, terminate with CRLF.CRLF> Hello, this is just a little test e-mail without any headers or anything.You can send whatever you like here, although you'll need to do some stuff withMIME if you want to send attachments or something.You end the message like this:.< 250 Mail has been queued for delivery> QUIT< 221 Goodbye.[Server closes connection]

It's fairly easy, and you can mostly get my with trial and error. If you desperately want to try sending mail using trial and error, I have a mail server (one I wrote myself) running at thetavern.servebeer.com, port 25. It'll accept all mail directed to someone @thetavern.servebeer.com.

Of course it's entirely possible that .NET has a function to send mail for you or something...
The C modest god
The C modest god
I dont want to have to ask the user for their server address, since I myself dont know what are my server address.
I will have to do with perhaps openning the default email program and filling it with the desired information? Is that possible? How do I do that?
It's all about the wheel.Never blindly trust technoligy.I love my internal organs.Real men don't shower. Quote: Original post by Toolmaker Quote:
Evil Steve
Evil Steve
This seems to work for me:
ShellExecute(NULL,"open","mailto:Steve@moo.com",NULL,"C:\\",SW_SHOWNORMAL);
You can probably append stuff like "&subject=Blah" or whatever, just as you do in a HTML link. I don't know if you can actually fill the message with information however.
Evil Steve
Evil Steve
Actually, this works fine:
ShellExecute(NULL,"open","mailto:Steve@moo.com?subject=My Subject&body=This is the message here",NULL,"C:\\",SW_SHOWNORMAL);
The C modest god
The C modest god
One last thing, how do I break a line inside the body text?
It's all about the wheel.Never blindly trust technoligy.I love my internal organs.Real men don't shower. Quote: Original post by Toolmaker Quote:
Pipo DeClown
Pipo DeClown
Evil Steve, that was a great explanation (post above), never knew that e-mail was that easy.. Hehe..
The C modest god
The C modest god
When I write the ...body=text" part, I would like to break down the lines.
However putting /r/n in the text does not break down the lines in the email program. How would I cause that the text in the body will be presented in the email program with line breaks?
It's all about the wheel.Never blindly trust technoligy.I love my internal organs.Real men don't shower. Quote: Original post by Toolmaker Quote:
Erzengeldeslichtes
Erzengeldeslichtes
Quote:
Original post by The C modest god
I dont want to have to ask the user for their server address, since I myself dont know what are my server address.
I will have to do with perhaps openning the default email program and filling it with the desired information? Is that possible? How do I do that?

If you don't need the user's e-mail, you can instead link into your own SMTP server and send an e-mail to yourself.
----Erzengel des Lichtes光の大天使Archangel of LightEverything has a use. You must know that use, and when to properly use the effects.♀≈♂?
Pipo DeClown
Pipo DeClown
Perhaps the HTML-tag BR would work? Anyway, some e-mail clients support multiple body vars which will end up as seperate lines:

&body=line1&body=line2..
The C modest god
The C modest god
I was told that SMPT is too low level for what I need and that I should use MAPI instead?
I looked for it in msdn but it says on all the results that the document is not found.
How can I use MAPI to achieve sending email?
Is there an other newer windows commands/interface I can use to achieve sending email?
It's all about the wheel.Never blindly trust technoligy.I love my internal organs.Real men don't shower. Quote: Original post by Toolmaker Quote:
Evil Steve
Evil Steve
Quote:
Original post by Pipo DeClown
Perhaps the HTML-tag BR would work? Anyway, some e-mail clients support multiple body vars which will end up as seperate lines:

&body=line1&body=line2..
Yeah, Google came up with that, but Outlook Express doesn't support it (it only sets the body to the last body= line), so thats a bit of a bummer.

I've never used MAPI, but I can't see it being much different from using a direct socket connection to the mail server. If you have a reasonable socket class, it's easy enough to parse a response line and to send what you need.
bytecoder
bytecoder
Actually, most mail servers require authentication, which require you to "log in" using the AUTH smtp command. Also note that you need to send the password in base64 encoded format (can't remember the specifics, it was a while ago when I experimented around with this stuff).

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.