Aspectacular.EmailHelper.SendSmtpEmail C# (CSharp) Method

SendSmtpEmail() public static method

Sends SMTP email using .config file settings.
public static SendSmtpEmail ( bool isBodyHtml, NonEmptyString optioanlFromAddress, NonEmptyString optionalReplyToAddress, string subject, string body ) : void
isBodyHtml bool
optioanlFromAddress NonEmptyString If null, .config from address value is used.
optionalReplyToAddress NonEmptyString If null, reply-to address is the same as from address.
subject string
body string
return void
        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);
            }
        }