/// <summary> /// Mail will be sent to error recipient if not LIVE. /// </summary> /// <param name="from"></param> /// <param name="to"></param> /// <param name="cc"></param> /// <param name="bcc"></param> /// <param name="subject"></param> /// <param name="body"></param> /// <param name="isBodyHtml"></param> /// <param name="preview">Force preview on LIVE system.</param> /// <param name="rethrow">Throw exception if sending fails. Must be set to false when sending exceptions.</param> /// <param name="attachments"></param> public Exception SendMailFrom(string @from, string @to, string cc, string bcc, string subject, string body, bool isBodyHtml, bool preview, bool rethrow, Attachment[] attachments, SmtpDeliveryMethod DeliveryMethod = SmtpDeliveryMethod.Network) { // Re-throw - throw the error again to catch by a caller try { var mail = new MailMessage(); SmtpClientEx.ApplyRecipients(mail, @from, @to, cc, bcc); SmtpClientEx.ApplyAttachments(mail, attachments); mail.IsBodyHtml = isBodyHtml; mail.Subject = subject; mail.Body = body; if (!IsLive || preview) { mail = GetMailPreview(mail); } if (DeliveryMethod == SmtpDeliveryMethod.SpecifiedPickupDirectory) { Smtp.SmtpDeliveryMethod = SmtpDeliveryMethod.SpecifiedPickupDirectory; Smtp.SmtpPickupFolder = SmtpClientEx.Current.SmtpPickupFolder; } Smtp.SendMessage(mail); return(null); } catch (Exception ex) { if (!string.IsNullOrEmpty(@to) && !ex.Data.Contains("Mail.To")) { ex.Data.Add("Mail.To", @to); } if (!string.IsNullOrEmpty(cc) && !ex.Data.Contains("Mail.Cc")) { ex.Data.Add("Mail.Cc", cc); } if (!string.IsNullOrEmpty(bcc) && !ex.Data.Contains("Mail.Bcc")) { ex.Data.Add("Mail.Bcc", bcc); } if (!string.IsNullOrEmpty(subject) && !ex.Data.Contains("Mail.Subject")) { ex.Data.Add("Mail.Subject", subject); } // Will be processed by the caller. if (rethrow) { throw; } else { ProcessException(ex); } return(ex); } }
/// <summary> /// Mail will be sent to error recipient if not LIVE. /// </summary> /// <param name="from"></param> /// <param name="to"></param> /// <param name="cc"></param> /// <param name="bcc"></param> /// <param name="subject"></param> /// <param name="body"></param> /// <param name="isBodyHtml"></param> /// <param name="preview">Force preview on LIVE system.</param> /// <param name="rethrow">Throw exception if sending fails. Must be set to false when sending exceptions.</param> /// <param name="attachments"></param> public void SendMailFrom(string @from, string @to, string cc, string bcc, string subject, string body, bool isBodyHtml, bool preview, bool rethrow, Attachment[] attachments) { // Re-throw - throw the error again to catch by a caller try { var mail = new MailMessage(); SmtpClientEx.ApplyRecipients(mail, @from, @to, cc, bcc); SmtpClientEx.ApplyAttachments(mail, attachments); mail.IsBodyHtml = isBodyHtml; mail.Subject = subject; mail.Body = body; if (!IsLive || preview) { mail = GetMailPreview(mail); } Smtp.SendMessage(mail); } catch (Exception ex) { if (!string.IsNullOrEmpty(@to) && !ex.Data.Contains("Mail.To")) { ex.Data.Add("Mail.To", @to); } if (!string.IsNullOrEmpty(cc) && !ex.Data.Contains("Mail.Cc")) { ex.Data.Add("Mail.Cc", cc); } if (!string.IsNullOrEmpty(bcc) && !ex.Data.Contains("Mail.Bcc")) { ex.Data.Add("Mail.Bcc", bcc); } if (!string.IsNullOrEmpty(subject) && !ex.Data.Contains("Mail.Subject")) { ex.Data.Add("Mail.Subject", subject); } // Will be processed by the caller. if (rethrow) { throw; } else { ProcessException(ex); } } }