Home » ASP.NET » Test Sending Email without a Server in ASP.NET

Test Sending Email without a Server in ASP.NET

back-041 By now, most people are familiar with the fact that ASP.NET will send mail from the codebehind by simply adding a few lines to your web.config file and adding another few lines of code in the codebehind file.

But it wasn’t until recently that I found that you don’t need to have access to an SMTP server to test your code.

In fact, this little trick will allow you to read the email without clogging up your email client with email you only wanted for testing purposes.

Instead of the normal entry of

    <smtp from="you@domain.com">
        <network host="maiServerl" password="password" 
           userName="loginName" port="25"/>

You can use

    <smtp from="you@domain.com"

This will drop your email message in the c:\mail directory as an *.eml file which you can open with Outlook Express.

The code you would write to send the mail is still the same:

SmtpClient smtp = new SmtpClient();
MailAddress from = new MailAddress(fromEmail, fromEmail);
MailAddress to = new MailAddress(emailAddress, emailAddress);
MailMessage message = new MailMessage(from, to);
message.Subject = SubjectLine;
message.Body = htmlString;
message.From = from;
message.IsBodyHtml = true;


Other post in ASP.NET

Related Post

  • Embedding Google Search Appliance Results in ASP.NETEmbedding Google Search Appliance Results in ASP.NET Several of the projects I’m involved with use the Google Search Appliance for their search engine.  For each of these projects, we’ve wanted to integrate the results on an ASPX […]
  • ASP.NET Dynamic ValidatorASP.NET Dynamic Validator One of the controls that was added to ASP.NET 3.5 in the SP1 release was the Dynamic Validator control.I completely missed it.What it does is pretty cool.  But it doesn’t […]
  • Magic Strings and Magic NumbersMagic Strings and Magic Numbers This past week a very old (last time I did work for him was in 2007) client of mine contacted me because their program suddenly started exhibiting a problem.  It seems that if a user […]
  • ASP.NET Server Performance TestingASP.NET Server Performance Testing loading... This happened a couple of years ago, but it is still relevant because I know of at least one place where it is still happening even though Microsoft has fixed the issue […]
  • What Browser Is Selenium Currently RunningWhat Browser Is Selenium Currently Running This probably doesn’t happen all that often, but this last week I came across the need to know which browser I was running my selenium test against.  I figured that buried deep in the […]

About Dave Bush

Dave Bush is a Full Stack ASP.NET developer focusing on ASP.NET, C#, Node.js, JavaScript, HTML, CSS, BootStrap, and Angular.JS.Does your team need additional help in any of the above? Contact Dave today.

One Pingback/Trackback