public static void SendEmail(EmailParameter ep) { using (MailMessage mm = new MailMessage()) { mm.From = new MailAddress(ep.from); AddEmail2MailAddressCollection(ep.toList, mm.To); AddEmail2MailAddressCollection(ep.ccList, mm.CC); AddAttachments(ep.attachmentPathList, mm.Attachments); mm.IsBodyHtml = ep.isBodyHtml; mm.Subject = ep.subject; if (!string.IsNullOrEmpty(ep.content)) { mm.Body = ep.content; } if (ep.htmlView != null) { mm.AlternateViews.Add(ep.htmlView); } mm.SubjectEncoding = ep.encoding; mm.BodyEncoding = ep.encoding; mm.Sender = new MailAddress(ep.from, ep.displayname, ep.encoding); ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(ValidateServerCertificate); SmtpClient smtpMail = new SmtpClient(ep.smtpServer); smtpMail.Credentials = new System.Net.NetworkCredential(ep.authenAccount, ep.authenPassword); smtpMail.Send(mm); } }
private static EmailParameter CreateEP() { EmailParameter ep = new EmailParameter(); ep.smtpServer = ConfigurationManager.AppSettings["MailServer"]; ep.authenAccount = ConfigurationManager.AppSettings["AuthenAccount"]; ep.authenPassword = ConfigurationManager.AppSettings["AuthenPassword"]; ep.from = ConfigurationManager.AppSettings["EmailFrom"]; ep.displayname = ConfigurationManager.AppSettings["DisplayName"]; return(ep); }
public static void SendEmail(List <string> toList, List <string> ccList, string subject, AlternateView htmlView) { EmailParameter ep = CreateEP(); ep.toList = toList; ep.ccList = ccList; ep.subject = subject; ep.encoding = Encoding.UTF8; ep.htmlView = htmlView; EmailHandler.SendEmail(ep); }
public static void SendEmail(List <string> toList, List <string> ccList, List <string> attachmentPathList, string subject, string content, bool isBodyHtml) { EmailParameter ep = CreateEP(); ep.toList = toList; ep.ccList = ccList; ep.attachmentPathList = attachmentPathList; ep.subject = subject; ep.content = content; ep.isBodyHtml = isBodyHtml; ep.encoding = Encoding.UTF8; EmailHandler.SendEmail(ep); }