Test Sending Email without a Server in ASP.NET
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
<mailSettings>
<smtp from="you@domain.com">
<network host="maiServerl" password="password"
userName="loginName" port="25"/>
</smtp>
</mailSettings>
You can use
<mailSettings>
<smtp from="you@domain.com"
deliveryMethod="SpecifiedPickupDirectory">
<specifiedPickupDirectory
pickupDirectoryLocation="c:\mail"/>
</smtp>
</mailSettings>
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.To.Add(to); message.IsBodyHtml = true; smtp.Send(message);
Other Related Items:
The Hills Have Eyes (Unrated Edition)Based on the original film by fright master Wes Craven, The Hills Have Eyes is the story of a family road trip that goes terrifyingly awry when the tr... Read More >
Sherry Rawn's It's Not Easy Being Cute Resin Doll: Anatomically Correct Miniature Baby Doll by The Ashton-Drake GalleriesRealistic Resin Baby Doll "Portrait" by Artist Sherry Rawn Has Adorable Personality! Includes FREE Matching Blanket! - What mom doesn't remember tryin... Read More >
Apple MacBook MC207LL/A 13.3-Inch LaptopThe MacBook uses a graphics processor that economizes space in a whole new way. A traditional computer logic board contains multiple components: the C... Read More >










[...] Test Sending Email without a Server in ASP.NET (Dave M. Bush) [...]