Testing email from localhost with ASP.NET without SMTP server
Alot of the time when developing web apps, you need to send emails from your application. Developers need a way to test this and sometimes you can’t be bothered to setup a local SMTP server just for this purpose. Thankfully, the ASP.NET framework has a built in way for you to set this up so you can send the emails to your hard drive as opposed to some SMTP server. Simply add the following code to your web.config and you should be good to go.
<system.net>
<mailSettings>
<smtp deliveryMethod="SpecifiedPickupDirectory">
<specifiedPickupDirectory pickupDirectoryLocation="c:\Temp\" />
</smtp>
</mailSettings>
</system.net>
That’s it! Pretty simple, just test it with some code like this
System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage("fromEmail@email.com",
“toEmail@email.com", “Test", “Test Body");
System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient();
client.Send(mail);
This will create and eml message file on your hard drive.
Leave a Comment
If you would like to make a comment, please fill out the form below.