How do I send an email

Started by
10 comments, last by swiftcoder 17 years, 11 months ago
Hiya I am using C++ and I want to send emails with my program, how would I go about doing this? Would I have to log into an existing email account? Are tehre any tutorials that could help me?
Whether you think you can or think you can’t, you’re probably right – Henry Ford
Advertisement
Quote:Original post by Peter Conn
and I want to send emails with my program


Why?
low level answer. Like Zahlman, I'm rather suspicious. What are you going to do with this program?
Google the SMTP protocol.
If youre using winsock you just connect to a smtp server and hand over
the information of the mail you want to send using smtp commands.
The SMTP protocol is really simple. You just connect to a mail server on port 25, and send text commands. Each line is terminated with \r\n (not just \n).
Example transaction:
220 Druinksoft SMTP server ready BIG TIME.HELO Test250 Hello Test [84.19.241.66]MAIL FROM:<Steve@Foo.com>250 OK, Sender AcceptedRCPT TO:<You@Bar.com>250 Ok, that is a valid mailbox.DATA354 Please start mail input.This is a test E-Mail. How exciting..250 Mail queued for delivery.QUIT221 Closing connection. Good bye.

When you send DATA, the server takes everything you send from then on, and sticks it into an e-mail. You tell it you're done by sending "\r\n.\r\n".
If you want a SMTP server to test on, feel free to use mine (thetavern.servebeer.com, port 25). I wrote it myself, so it might not be 100% accurate to the spec, but it works well enough for my needs [smile]

My SMTP server won't relay any mail though (I keep getting spammed by test bots...). If you want to actually do this in final code, you'll need to either look up the MX record of the target server (which is hard), or just send the e-mail to your ISPs SMTP server, and they'll relay it for you. But the program will need to know the SMTP server of the end user, which might be a pain to try and get.
As for why I asking is because there's this piece of software called SEO Elite that searchs something on google and then automatically emails requests for reciprotal (spelling?) links to the webmasters (aswell as some other stuff). I just wanted to see if I could make a program that could read two text files, one with the message and one with a list of websites. It would then read the list and go through a loop and send an email to each of the webmasters. Therefore saving time and money.

Btw why would you be suspicious of this post?
Whether you think you can or think you can’t, you’re probably right – Henry Ford
Proably because we aren't too keen on recieving this sort of emails about our websites [grin]

Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]

I suppose, but then if you've searched SEO on google there are loads of forums and stuff about it.
Whether you think you can or think you can’t, you’re probably right – Henry Ford
Quote:Original post by Peter Conn
Btw why would you be suspicious of this post?


Because that's exactly the sort of thing that spammers want to use (of course, they already have plenty of options out there), and it's not really a common request.

Anyway, it is probably more "normal" to shell out to another program for this sort of thing (such as Unix 'sendmail'). It's also probably much better done in a scripting language rather than in C++.
Quote:Original post by Peter Conn
I just wanted to see if I could make a program that could read two text files, one with the message and one with a list of websites. It would then read the list and go through a loop and send an email to each of the webmasters. Therefore saving time and money.


It might be easier to do this (or other things involving manipulating text files) in a scripting language like perl than C++. Here is a link explaining some of the ways perl handles email.

This topic is closed to new replies.

Advertisement