Monday, December 12, 2016

Trapping emails generated in C# when there is no SMTP server

If you need to generate emails in your app, I’ve found a way to test them in the dev environment. Visit http://smtp4dev.codeplex.com/downloads/get/269147 and download the tool. The executable in the ZIP file will spawn a mini-smtp server. Click the “options” button and then the “server” tab. Set the listen interface to 127.0.0.1, I think you can leave the port at 25.
Add the following to your web.config file in the <configuration> section. Port will be whatever number you specified for smtp4dev:
<system.net>
   <mailSettings>
     <smtp>
       <network host="localhost" port="25" />
     </smtp>
   </mailSettings>
</system.net>
Write your code as normal to generate & send the email. Smpt4dev will notify you that you’ve received an email and you can click the “view” button to see the email message in Outlook.
The app sits in the tool tray under “hidden icons”, so no need to start the executable again. Closing the smpt4dev UI doesn’t end the process and running the exe again will produce a “server failed” message as shown below. View hidden icons in the tool tray close any extra occurrences of smtp4dev.

2 comments:

alina said...

You can also opt out of receiving LinkedIn's job notifications and news articles. You can even turn off the notifications when you're offline. This is one way to avoid spamming others on your network. Do you want to know more about linkedin emails? for detailed info click here now.

alina said...
This comment has been removed by the author.