tags:

views:

24

answers:

1

I have an application that sends 500K+ transactional emails a month. Some are more important than others. I need the important emails to go out using a high-delivery email solution with tracking (read more expensive) and the less important emails using an ordinary mail server.

Is there a way setup multiple smtp sections in mailSettings pointing to the two mail servers and let the code choose which mail server they want to do the sending with.

There is a way to do it using the "location" and have the pages handle sending the email pick the smtp server based on the path. However I have a separate background process forked that is doing this asynchronously and this will not help much.

Thanks!

+1  A: 

Instead of using mailsettings, perhaps look into using appsettings to store your server connection strings.

<appSettings>
   <add key="SmtpServer.Fast" value="fast.smtp.mycompany.com" />
   <add key="SmtpServer.Slow" value="slow.smtp.mycompany.com" />
</appSettings>

Then just use new SmtpClient(server) instead of new SmtpClient() Then you could set up your code to be something like:

SmtpClient client = null;

if (IsHighPriorityMessage(msg))
  client = new SmtpClient(ConfigurationManager.AppSettings["SmtpServer.Fast"]);
else
  client = new SmtpClient(ConfigurationManager.AppSettings["SmtpServer.Slow"]);

If you need to configure authentication, just use client.Credentials

Shaun McCarthy
Thanks. There are many ways to do it and this is one of them. We are doing something similar now. As you can imagine there is more than just the MTA name - one of them uses ESMTP so we need to also have the user/pass/port settings.
taazaa