public void Send(Message msg)
{
Tracing.Information("[SmtpMessageDelivery.Send] sending mail to " + msg.To);
if (!String.IsNullOrWhiteSpace(msg.Cc))
{
Tracing.Information("[SmtpMessageDelivery.Send] cc'ing mail to " + msg.Cc);
}
if (String.IsNullOrWhiteSpace(msg.From))
{
SmtpSection smtp = ConfigurationManager.GetSection("system.net/mailSettings/smtp") as SmtpSection;
msg.From = smtp.From;
}
using (SmtpClient smtp = new SmtpClient())
{
smtp.Timeout = SmtpTimeout;
try
{
MailMessage mailMessage = new MailMessage(msg.From, msg.To, msg.Subject, msg.Body)
{
IsBodyHtml = SendAsHtml
};
if (!String.IsNullOrWhiteSpace(msg.Cc))
{
foreach (string email in msg.Cc.Split(',', ';'))
{
mailMessage.CC.Add(email);
}
}
smtp.Send(mailMessage);
}
catch (SmtpException e)
{
Tracing.Error("[SmtpMessageDelivery.Send] SmtpException: " + e.Message);
}
catch (Exception e)
{
Tracing.Error("[SmtpMessageDelivery.Send] Exception: " + e.Message);
}
}
}
}