Cjwdev.Mail.SmtpSender

November 6, 2009 — 1 Comment

As mentioned in the previous post, I have begun writing my own .NET SMTP server class that I will be making available for free (in the form of a .NET DLL) on my website once complete. So lets take a look at exactly what this class is for and how it will work:

My SMTP class library can essentially turn your application into an SMTP server. It will provide the ability to send emails (without the need for an existing SMTP server) and will allow your application to handle incoming SMTP requests from other servers and clients.

Obviously there is nothing in the .NET framework already for receiving SMTP messages because that is not a very common thing to want to do in an application (basically, only an email server would need to do this… and how many people write one of those). However there is already the System.Net.Mail.SmtpClient class for sending emails via SMTP. So you may be wondering why I’m creating my own version that does the same thing… well the answer is:  I’m not! My class will be totally different to the SmtpClient class because the SmtpClient class simply passes a message to the SMTP server you specify and then it is up to that server to find the email server that handles incoming mail for the domain you are sending an email to and then deliver it to that server. My class will do all of that itself – it will perform an MX lookup to find the email server for the domain you are sending the email to and then it will transfer the SMTP message directly to that server. This means you do not have to specify an SMTP server at all because my class IS the SMTP server – using my class you could do something as simple as this to send an email (the syntax has not been finalised yet but you get the idea):

Dim MySmtpServer As New SmtpSender
MySmtpServer.Send(me@mydomain.com, recipient@theirdomain.com, _
"subject here", "body of email here")

In case you are wondering, the reason the class is named SmtpSender rather than just SmtpServer is because there will be a separate class for receiving incoming SMTP requests (named SmtpReceiver). Both of these classes will be part of the same class library but having them both in their own separate classes means that a developer looking just to use the sending function does not need to worry about anything to do with the receiving side of things, and vice versa.

To further illustrate the differences between what I am creating and the built-in SmtpClient class, take a look at the following diagrams, the first shows what happens when you send an email using the SmtpClient class and the second shows how my SmtpSender class works:

SmtpClient

Step 1. The email is transferred to the SMTP server that was specified when setting up the SmtpClient instance

Step 2. The SMTP server queries a DNS server for the MX (mail exchanger) records for somedomain.com, the DNS server responds with the external name/IP addresses of the servers that handle incoming email for somedomain.com

Step 3. The SMTP server attemtps to transfer the email to the server that the DNS server told it was responsible for handling incoming emails for somedomain.com

Now here is a diagram showing what happens with my SmtpSender class:

SmtpSender

Step 1. The SmtpSender class queries a DNS server for the MX records for somedomain.com, the DNS server responds with the address of the email server for that domain

Step 2. The SmtpSender class attempts to transfer the email to the email server responsible for incoming email for somedomain.com

So as you can see, this is not simply my own version of SmtpClient – it serves a similar purpose (to send an email) but goes about it in a different way. I am not saying that this is better than SmtpClient, there will be times when SmtpClient will be the better choice but at least with my class available you will have a choice. You can either use SmtpClient to pass the email to a dedicated SMTP server for sending (and in some business networks, firewall rules and other restrictions will mean that this is your only choice) or you can have your application send the email directly without having to rely on another SMTP server being available.

Hopefully that explains the sending side of things, the next post will describe how the SmtpReceiver class will work.

Trackbacks and Pingbacks:

  1. Cjwdev.Mail Alpha Release Download Available « Cjwdev - January 22, 2010

    […] Cjwdev.Mail Alpha Release Download Available As mentioned in the previous post, the Cjwdev.Mail.SmtpSender class is now ready for public testing. See below for download link and instructions. If you dont know what this SmtpSender class is, you can read all about it here: SmtpSender Class Description […]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s