Cjwdev.Mail Alpha Release

January 22, 2010 — 5 Comments

The ALPHA release (pre-BETA) of the Cjwdev.Mail class SmtpSender is now ready for public testing and will be available for download within the next couple of days. This is still early days and the code is certainly not ready to be used in any real applications, I am just releasing it in this early form to get feedback and to see if other people can find bugs in it that I have not yet found or anticipated (there will undoubtedly be a fair few of these!). An example of how to use the SmtpSender class can be found below.

Here is a very simple example of how you can use the SmtpSender class (which is the class I have been focusing on, whilst other classes are included in this release I suggest ignoring them for now) once you have added a reference to the SmtpSrv.dll file. Note that the SmtpSrv DLL uses functions from the MxResolver DLL so although your project does not need to directly reference MxResolver.dll, you must make sure you have that DLL in the same folder as SmtpSrv.dll.

'Create the SmtpSender instance
Dim Smtp As New Cjwdev.Mail.SmtpSender()

'Build our list of recipients
Dim RecipientList As New List(Of String)
RecipientList.Add("example@example.com")
RecipientList.Add("example@anotherexample.co.uk")

'Send the email
Smtp.SendEmail("cwright@cjwdev.co.uk", RecipientList, "This is the subject", "This is the body of the email message")

Thats it, no need to specify any SMTP server because the application is doing all of the work of an SMTP server itself. What IS required though is a DNS server – if you use the parameterless constructor of SmtpSender as I have done in that example though, the code will automatically pick up the DNS server that your PC is already using. Of course there are overloaded constructors where you can set a specific DNS server as well.

The SendEmail method is actually a function that returns a List(Of SendEmailResult) and as such you can check this list once the method returns to see which of your recipients the code was able to successfully send emails to. Here is an extended example showing how to do this:

'Create the SmtpSender instance
Dim Smtp As New Cjwdev.Mail.SmtpSender()
'This ID is used to identify us to the remote server – some SMTP servers require this
Smtp.LocalIdentifier = "mydomain.com"

'Build our list of recipients
Dim RecipientList As New List(Of String)
RecipientList.Add("example@example.com")
RecipientList.Add("example@anotherexample.co.uk")

'Send the email and loop through the results
For Each SendResult As SendEmailResult In Smtp.SendEmail("""Chris Wright"" <cwright@cjwdev.co.uk>", RecipientList, "This is the subject", "This is the body of the email message")
    'Show the results for this recipient in a messagebox
    MessageBox.Show(SendResult.Recipient & vbNewLine & SendResult.Result.ToString & _
                    vbNewLine & SendResult.ErrorInformation)
Next

'Example output if a DNS error occurred:
'recipient@example.com
'DnsError
'The DNS server returned the error message NOT IMPLEMENTED which _
'indicates that the DNS server does not support the type of query that was sent to it.

'Example output if successful:
'another.recipient@example.com
'MailSubmittedSuccessfully
'No Error

I will post another blog post as soon as the download link is available, but be sure to let me know if you have any feedback about the syntax for the SmtpSender class or have any comments on the Cjwdev.Mail library in general.

5 responses to Cjwdev.Mail Alpha Release

  1. 

    This looks great, Chris. I can’t wait to test it out 😀

  2. 

    Are you releasing the source?

Trackbacks and Pingbacks:

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

    […] 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 […]

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