Is there anyway to have all emails go to a different address when System.Web.HttpContext.Current.IsDebuggingEnabled is true? Or do I need a new class which I use to send email everywhere?
Is there anyway to have all emails go to a different address when System.Web.HttpContext.Current.IsDebuggingEnabled
Share
We use a similar solution to the MailProxy method detailed by tvanfosson. However we have a few differences that I feel are worth mentioning. The first is that we simply extend the SmtpClient class and override the Send methods when in a development or testing environment. We use a config file to determine the environment. We then use this class anytime we need to send out emails. This class will determine who is currently logged into the application and redirect all emails generated to them, with a failover to a standard list of recipients if the logged in user is not available for whatever reason. This helps if you have several people who are testing or developing as they will only get the emails they generated. We also prepend the original recipients of the message to the body of the message. This again is useful when testing workflow type messages to ensure that they are going to the correct individuals. Finally, I find it’s useful to add a [DEV] or [QA] tag to the subject of the message so I can set up a rule in my mail client to handle all testing messages.