Thu, Oct 25, 2012

Testing your application’s email logic

If you’ve ever written an application that sends out email you may have written the code and executed it numerous times to check that the logic works and that the email appears as you hope. This obviously means you have to hit your SMTP server each time, open your email client and check your emails each time.


Reading through my Twitter timeline I saw @TheCodeJunkie asking about the app that you can use to test sending emails from your application.

TheCodeJunkie Tweet

Intrigued, I kept an eye on my timeline and found that the application in question was Papercut

In simple terms you put Papercut on a machine (most likely your development machine) and in your code set the SMTP host to be the IP Address of where Papercut is running and fire up your application and watch Papercut notify you from the system tray that it’s recevied a message.

Papertray System Tray Icon

Papertray System Tray Icon

Lets open it up and see what it says!

Raw View

Raw View

Body View

Body View

I’ve tested this with a C# application and a Node.js application. If you don’t believe me, here’s the code:


static void Main(string[] args)
	MailMessage message = new MailMessage("Jonathan Channon ", "")
        Subject = "iPhone",
        Body = "I would like a free iPhone for work. My boss won't let me have one. How about it?",
        BodyEncoding = Encoding.UTF8
	SmtpClient client = new SmtpClient("");
	NetworkCredential info = new NetworkCredential("", "reallysecurepassword");
	client.DeliveryMethod = SmtpDeliveryMethod.Network;
	client.UseDefaultCredentials = false;
	client.Credentials = info;
	catch(Exception ex)


var nodemailer = require("nodemailer");

var smtpTransport = nodemailer.createTransport("SMTP");

var mailOptions = {
    from: "Jonathan Channon ",
    to: "",
    cc: "",
    subject: "iPhone",
    text: "I would like a free iPhone for work. My boss won't let me have one. How about it?",
    html: "I would like a free iPhone for work. My boss won't let me have one. How about it?"

smtpTransport.sendMail(mailOptions, function(error, response){
        console.log("Message sent: " %2B response.message);


I think this is a great little app and a real time saver. I highly recommend that you check it out!

They also offer a web based version called DummySMTP which allows you to test an almost live copy of your application but DummySMTP captures the emails sent out to customers, for example.

comments powered by Disqus