You had me at ehlo!

It seems that a lot of websites send users email for lots of reasons. This introduces a bit of a problem when you are developing applications because as developers we don't necessarily want to put an smtp server on our development machine and network administrators are fairly selective about the open SMTP relays that they want on their network.

ASP.net has a solution, and I have a solution.

The asp.net solution is that the web server where your application will eventually live can (will) have a single machine configuration for the smtp settings. Every application can override this setting in the web.config file, but should actually just comment out the <mailsettings> section.

During development, however, this configuration is useful:

<configuration>
<system.net>
<mailSettings>
<smtp from="admin@foo.bar" deliveryMethod="SpecifiedPickupDirectory">
<specifiedPickupDirectory pickupDirectoryLocation="C:\pickup" />
</smtp>
</mailSettings>
</system.net>
</configuration>


This will just dump the emails in the C:\pickup directory of your development machine. No need to install the SMTP service on your computer at all! This only works with the email classes in System.Net.Mail.

If you use System.Web.Mail.SmtpMail you are out of luck because it defaults to using a network delivery and localhost as the server. That is where my other solution comes in...

I wrote a quickie program a few years ago that I call "Black Hole" because it sucks up everything you send at it and doesn't let anything out. It is a stand alone SMTP server that just can either silently eat messages, or it can log the communication with your smtp client, and optionally dump the email messages do a directory.



You can download it here.

The zip file contains a stand-alone executable (written in Delphi) that will listen on whatever port you tell it and whatever ip addresses you want. Then, just configure your web.config (or app.config for that matter) settings to point to localhost with no credentials needed.

Comments

Popular posts from this blog

Database Projects, SQL Unit Tests, and TeamCity

Building nice XML from SQL Server Tables

Brent: Programmer. Gamer. Cheapskate. All around good guy.