Learning WinSock and SMTP

Getting to grips with sockets programming and using SMTP

© Guy Lecky-Thompson

Mar 14, 2007

For those who have never sent an email using Telnet, or connected sockets to servers in C, this is how to do it.


I recently got involved in a project that required sending email alerts, and knew very little going in about the ins and outs of socket programming under Windows, let alone how to send an email without recourse to Outlook Express.

To say that it took some research is an understatement.

As it turns out, you can send email through Telnet. Now, that's out of the scope of this little introduction to SMTP and WinSock programming, but it is a great starting point. If you ever need to check what a server can do, basic Telnet is a great way to find out.

So, with that in mind, a quick delve into the world of WinSock programming made it clear that it requires (a) getting an IP address from a server name (mail.yourisp.com), (b) connect it to a socket, and (c) dialoging with the server.

The exact nature of the dialog depends on the server in question. For an SMTP server, there are commands to authenticate with the server, with username and password, prepare a message with email addresses, subject line, and body.

Having fought with the documentation available on the Internet, and played around Telnetting to mail servers for a few hours, I decided to help out my fellow programmers and write it up.

The article in question can be found here : computer-programming-tutorials.suite101.com/article.cfm/sending_email_with_smtp_auth

Have fun!


Post this Blog to facebook Add this Blog to del.icio.us! Digg this Blog furl this Blog Add this Blog to Reddit Add this Blog to Technorati Add this Blog to Newsvine Add this Blog to Windows Live Add this Blog to Yahoo Add this Blog to StumbleUpon Add this Blog to BlinkLists Add this Blog to Spurl Add this Blog to Google Add this Blog to Ask Add this Blog to Squidoo