Important note: Source Code was moved to github: (https://github.com/cmendible/netDumbster)

Project Description
netDumbster is a .Net Fake SMTP Server clone of the popular Dumbster (http://quintanasoft.com/dumbster/)

netDumbster is based on the API of nDumbster (http://ndumbster.sourceforge.net/default.html) and the nice C# Email Server (CSES) written by Eric Daugherty.

Follow us:
(www.hexasystems.com)
(www.twitter.com/hexasystems)
(carlos.mendible.com)

The following sample shows how to use netDumbster in a MbUnit (http://www.gallio.org/) test.

using System;
using System.IO;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Mail;

using Gallio.Framework;
using MbUnit.Framework;

using netDumbster.smtp;

namespace netDumbster.Test
{

	[TestFixture]
	public class Tests
	{
		private static SimpleSmtpServer _Server;
		private Random _Rnd = new Random();

		public Tests()
        {
            log4net.Config.XmlConfigurator.Configure();
        }

		private void SendMail()
		{
			SendMail(false);
		}

		private void SendMail(bool smtpAuth)
		{
			SmtpClient client = new SmtpClient("localhost", _Server.Port);
			var mailMessage = new MailMessage("cfm@mendible.com", "kbm@mendible.com", "test", "test tes test");

			if (smtpAuth)
			{
				NetworkCredential credentials = new NetworkCredential("user", "pwd");
				client.Credentials = credentials;
				client.EnableSsl = false;
			}
			
			client.Send(mailMessage);
		}

		[FixtureSetUp]
		public void FixtureSetUp()
		{
			_Server = SimpleSmtpServer.Start(_Rnd.Next(50000, 60000));
		}

		[FixtureTearDown]
		public void FixtureTearDown()
		{
			_Server.Stop();
		}

		[SetUp]
		public void SetUp()
		{
			_Server.ClearReceivedEmail();
		}

		[Test]
		public void Send_One_Mail()
		{
			SendMail();
			Assert.AreEqual(1, _Server.ReceivedEmailCount);
		}

		[Test]
		public void Send_One_Mail_With_SmtpAuth()
		{
			SendMail(true);
			Assert.AreEqual(1, _Server.ReceivedEmailCount);
		}

		[Test]
		public void Send_100_Mail_With_SmtpAuth()
		{
			for (var i = 0; i < 100; i++)
			{
				SendMail(true);
				Assert.AreEqual(i + 1, _Server.ReceivedEmailCount);
			}
			Assert.AreEqual(100, _Server.ReceivedEmailCount);
		}

		[Test]
		public void Send_100_Mails()
		{
			for (var i = 0; i < 100; i++)
			{
				SendMail();
				Assert.AreEqual(i +1, _Server.ReceivedEmailCount);
			}
			Assert.AreEqual(100, _Server.ReceivedEmailCount);
		}
	}
}

Last edited Sep 12, 2011 at 11:15 AM by cmendible, version 7