Question

I have an ASP.NET 2 application that sends email to specific users to notify them of certain events. The application uses the System.Net.Mail.SmtpClient class to construct the email and send it.

Whilst developing and testing the application I'd like to make sure we aren't sending emails to the production email addresses. I'd like to avoid branching in the application code (e.g. using compiler directives and build configurations) as this means not all code paths can be tested until we deploy the application to the production environment. Ideally I'd like to configure the application in development to use a development SMTP server host that takes all email and sends it to a specific address regardless of the address it was instructed to send to. Is this possible using Windows XP / IIS 5?

What other approaches could be taken in this scenario.

Was it helpful?

Solution

One aproach is get like a flag test or something, so that according to whats configured for example in web.config you send the email to test email assigned by you.

But in my opinion, this is a bit of hack, an alternative and more recommended solution would be set DeliveryMethod to SmtpDeliveryMethod.SpecifiedPickupDirectory in web.config and specify a directory for your messages to be saved, so instead of actually sending the email, you just create it and place it in a folder so you can check it out. This way you can have one web.config for testing and the other one for production that has DeliveryMethod set as Network with all production smtp settings.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top