Instead of using email settings, perhaps consider using the appsettings settings to store connection strings for the server.
<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 new SmtpClient(). Then you can configure the code this way:
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
source
share