The Artima Developer Community
Sponsored Link

.NET Buzz Forum
A Simple SMTP Server Mock for .NET

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Igor Milovanovic

Posts: 18
Nickname: sn0wcat
Registered: May, 2004

Igor Milovanovic is a software architect and .NET author.
A Simple SMTP Server Mock for .NET Posted: Sep 28, 2004 4:59 PM
Reply to this message Reply

This post originated from an RSS feed registered with .NET Buzz by Igor Milovanovic.
Original Post: A Simple SMTP Server Mock for .NET
Feed Title: Igor Milovanovic
Feed URL: /error.aspx?aspxerrorpath=/imilovanovic/category/991.aspx/rss
Feed Description: .NET, cats and more...
Latest .NET Buzz Posts
Latest .NET Buzz Posts by Igor Milovanovic
Latest Posts From Igor Milovanovic

Advertisement

A SMTP server mock is basically a fake SMTP server which can be used for unit testing of applications which send email messages. It acts as a real smtp server, except that  the incoming messages are locally stored and not actually delivered .  This can be quite usefull if you are using real data for testing. ;-) 

   1:  [Test]
   2:  public void MailTest ()
   3:  {
   4:      SmtpMock smtpServerMock = new SmtpMock ();
   5:      smtpServerMock.Start();
   6:      System.Web.Mail.SmtpMail.SmtpServer = "localhost";
   7:      System.Web.Mail.SmtpMail.Send("somebody@foo.com", "everybody@bar.com", "This is the subject", "This is the body.");
   8:      smtpServerMock.Stop ();
   9:   
  10:      Assert.AreEqual (1, smtpServerMock.Sessions.Count);
  11:      SmtpSession session = (SmtpSession) smtpServerMock.Sessions[0];
  12:      Assert.IsTrue (session.SessionProtocol.IndexOf("somebody@foo.com") > 0 );
  13:      Assert.IsTrue (session.SessionProtocol.IndexOf("everybody@bar.com") > 0 );
  14:      Assert.IsTrue (session.SessionProtocol.IndexOf("This is the subject") > 0 );
  15:      Assert.IsTrue (session.SessionProtocol.IndexOf("This is the body.") > 0 );
  16:   
  17:  }

Example: Unit-Test with SMTP-Server Mock

As I couldn't find a .NET implementation (take a look at dumbster for java version), I decided to write one myself. The implementation is very simple as it only opens a listener at port 25 and responds to pretty much anything with 250 OK. ;-) . The recieved emails are stored in SessionProtocol (see example).

[1] Dumbster - Fake SMTP Server for Java
[2] SmtpMock.cs

 

Read: A Simple SMTP Server Mock for .NET

Topic: How to Configure WSE 2.0 Services Behind a NAT Router. Previous Topic   Next Topic Topic: First meeting - so hard to find a day !

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use