// ------------------------------------------------------------------------------- // GetMailBody // ------------------------------------------------------------------------------- protected string GetMailBody(MailTemplateType templateType, int nCode) { TextAsset textAsset; string sBody = ""; if (dictMailTemplates.TryGetValue((int)templateType, out textAsset)) { sBody = textAsset.ToString(); sBody = sBody.Replace("{0}", nCode.ToString()); } return(sBody); }
public string GetTemplate(MailTemplateType mailType) { switch (mailType) { case MailTemplateType.Newsletter: return(File.ReadAllText(NewsletterPath)); case MailTemplateType.ProductQuestion: return(File.ReadAllText(ProductQuestionPath)); default: throw new UnknownEmailMessageType(mailType.GetType()); } }
// ------------------------------------------------------------------------------- // SendMail // ------------------------------------------------------------------------------- protected void SendMail(string sRecipientEmailAddress, MailTemplateType templateType, int nCode) { MailMessage message = new MailMessage(); message.To.Add(sRecipientEmailAddress); message.From = new MailAddress(eMailAddress); message.Subject = eMailSubject; message.IsBodyHtml = true; message.Body = GetMailBody(templateType, nCode); SmtpClient smtp = new SmtpClient(); smtp.UseDefaultCredentials = false; smtp.Host = smtpServerHost; smtp.Port = smtpPort; smtp.EnableSsl = smtpEnableSSL; smtp.Credentials = new NetworkCredential(eMailAddress, eMailPassword) as ICredentialsByHost; smtp.SendAsync(message, message); }