Saturday, April 02, 2011

Simulating sending email

This is not new but very helpful if you build applications and in the business process need to send emails.

The old way that I was using is to go inside the code and remark some lines and put my email instead of the receiver and make some tests and see the email in my inbox, sometimes we forget to update that part and when we go to production emails come to my inbox or other problems that can appear because we marked some code.

So better than that change the email configuration in the web config to something like the following:

      <smtp deliveryMethod="SpecifiedPickupDirectory">
        <network host="ignored" />
        <specifiedPickupDirectory pickupDirectoryLocation="c:\email" />
After running and sending email you will get these emails in a directory and you can check them with there there format. This will even be helpful if you don’t have the email server setting at the time your developing.

In the end when you go to production only use the correct web.config file setting. In my work I don’t deploy my testing web.config because of all the db connection setting and other stuff. So when you test your application locally you will receive the emails in the C:\email directory and when you go to production it will be there for you working without the need to change code, recompile and test.

1 comment:

  1. Anonymous1:59 am

    Great tip Ali. Thanks for sharing.
    Aftab Ahmed Kalhoro