The tip I am going to share today is an old one but many developers do not know about it. Assume you are creating an application and need to test a module that sends out bulk mails, like a newsletter. Your first thought would be to configure an SMTP server to test the email module. However there is a trick that you can make use of while testing your code. Use the following setting in your web.config
The specifiedPickupDirectory element configures the local directory for a Simple Mail Transport Protocol (SMTP) server. The pickupDirectoryLocation is a directory where the application saves e-mail for later processing by the SMTP server. Make sure the directory exists before using it.
That’s it. Test this setting using the following code:
protected void btnMail_Click(object sender, EventArgs e)
MailMessage message = new MailMessage("firstname.lastname@example.org",
"Newsletter", "This is a test mail");
SmtpClient client = new SmtpClient("localhost");
Run the application and click on the Send button. Now open the Mails folder in your C Drive and you should see your mail there. Similarly you can test your entire newsletter module without sending out mails to real email addresses.
Cool ain’t it! Just make sure that if you are using IIS, it should have read-write permissions to this folder.
Giving me +1 tells me you liked this article! Thanks in advance
Did you like this post?
|Save on Delicious|
|subscribe via rss||subscribe via e-mail|
|print this post||follow me on twitter|