public static void SendSmtpEmail(bool isBodyHtml, NonEmptyString optioanlFromAddress, NonEmptyString optionalReplyToAddress, string subject, string body, params string[] toAddresses)
{
if(toAddresses != null)
toAddresses = toAddresses.Where(addr => !addr.IsBlank()).ToArray();
if(toAddresses.IsNullOrEmpty())
throw new Exception("\"To\" address must be specified");
if(subject.IsBlank() && body.IsBlank())
throw new Exception("Both subject and message body cannot be blank.");
MailMessage message = new MailMessage();
if(optioanlFromAddress != null)
message.From = new MailAddress(optioanlFromAddress);
if(optionalReplyToAddress != null)
message.ReplyToList.Add(new MailAddress(optionalReplyToAddress));
toAddresses.ForEach(toAddr => message.To.Add(new MailAddress(toAddr)));
message.Subject = subject;
message.Body = body;
message.IsBodyHtml = isBodyHtml;
SmtpClient smtpClient = SmtpClientFactory == null ? null : SmtpClientFactory();
if(smtpClient == null)
smtpClient = new SmtpClient();
using(smtpClient)
{
smtpClient.Send(message);
}
}