public static async Task <bool> SendEmail(General.Model.EmailAddress FromEmail, List <General.Model.EmailAddress> Recipients, string Subject, string Body, bool IsHtml = false, List <string> Attachments = null, bool SendWithBCC = true) { MailMessage objMailMessage = new MailMessage(); #region From/To objMailMessage.From = new MailAddress(FromEmail, FromEmail.Name); if (Recipients == null || Recipients.Count == 0) { return(false); } else if (Recipients.Count == 1) { General.Model.EmailAddress objEmail = Recipients.First(); if (StringFunctions.IsNullOrWhiteSpace(objEmail.Name)) { objMailMessage.To.Add(objEmail.Value); } else { objMailMessage.To.Add(new MailAddress(objEmail, objEmail.Name)); } } else if (Recipients.Count > 1) { foreach (General.Model.EmailAddress objEmail in Recipients) { if (objEmail != null) { if (objEmail.Valid) { if (SendWithBCC) { if (StringFunctions.IsNullOrWhiteSpace(objEmail.Name)) { objMailMessage.Bcc.Add(objEmail.Value); } else { objMailMessage.Bcc.Add(new MailAddress(objEmail, objEmail.Name)); } } else { if (StringFunctions.IsNullOrWhiteSpace(objEmail.Name)) { objMailMessage.To.Add(objEmail.Value); } else { objMailMessage.To.Add(new MailAddress(objEmail, objEmail.Name)); } } } } } } #endregion #region Message Content objMailMessage.Subject = Subject; objMailMessage.Body = Body; if (!String.IsNullOrEmpty(Body) && (Body.ToLower().Contains("<br") || Body.ToLower().Contains("<div") || Body.ToLower().Contains("<body"))) { IsHtml = true; } objMailMessage.IsBodyHtml = IsHtml; #endregion #region Attachments if (Attachments != null) { foreach (string s in Attachments) { if (System.IO.File.Exists(s)) { Attachment objAttachment = new Attachment(s); objMailMessage.Attachments.Add(objAttachment); } } } #endregion #region Send Asynchronously using (System.Net.Mail.SmtpClient objMailServer = ErrorReporter.GetEmailServer()) { try { await objMailServer.SendMailAsync(objMailMessage).ConfigureAwait(false); return(true); } catch { return(false); } } #endregion }