Email testing in Ruby On Rails application is very easy because of the Action Mailer framework.

However, .NET does not have such similar framework. After doing a series of research, I finally found something that could help a little – netDumsbter.

netDumsbter merely is a fake .NET SMTP server derived from Dumsbter which is popular for Java based applications.

We will use System.Net.Mail to as the SMTP client to send emails.

The example below is how netDumsbter is used:


#Initialises a new SMTP server
SimpleSmtpServer _Server;

#Starting the server at a random port each time, else it will throw errors
Random _Rnd = new Random();
_Server = SimpleSmtpServer.Start(_Rnd.Next(50000, 60000));

#Initialise a SMTP client by using the .Net “System.Net.Mail” library
SmtpClient client = new SmtpClient(“localhost”, _Server.Port);

#Creating a new email message and send it using the System.Net.Mail function
var mailMessage = new MailMessag(“cfm@mendible.com”, “kbm@mendible.com”, “test”, “test tes test”);
client.Send(mailMessage);

#Prints out how many email received via the fake SMTP server. In this example, we will get 1
Console.Write(_Server.ReceivedEmailCount);

#Stopping the server
_Server.Stop();

Conclusion

– .Net does not provide a good framework for email testing automation like Ruby

– The combination of netDumster and System.Net.Mail is good for unit testing purposes but not integration or functional testing