public void SendEmail(CreateEmailMessage emailMessage) { try { var body = TemplateManager.Fill(TemplateManager.GetTemplate(emailMessage.BodyTemplate), emailMessage.BodyData); MailMessage mailMsg = new MailMessage(); mailMsg.To.Add(emailMessage.Address); mailMsg.From = new MailAddress(emailMessage.Sender); // Subject and multipart/alternative Body mailMsg.Subject = emailMessage.Subject; mailMsg.AlternateViews.Add(AlternateView.CreateAlternateViewFromString(body, null, MediaTypeNames.Text.Html)); // Init SmtpClient and send SmtpClient smtpClient = new SmtpClient(SmtpConfig.SmtpServer, Convert.ToInt32(SmtpConfig.Port)); if (!string.IsNullOrEmpty(SmtpConfig.Username)) { System.Net.NetworkCredential credentials = new System.Net.NetworkCredential(SmtpConfig.Username, SmtpConfig.Password); smtpClient.Credentials = credentials; } smtpClient.Send(mailMsg); } catch (Exception ex) { throw ex; } }
public string PostEmail(CreateEmailMessage email) { if (string.IsNullOrEmpty(email.Id)) { email.Id = Guid.NewGuid().ToString(); } Bus.Send(email); return(email.Id); }
public void Handle(CreateEmailMessage message) { EmailSender.SendEmail(message); }
public string Email([FromBody] CreateEmailMessage createEmailMessage) { Trace.WriteLine(createEmailMessage); return(MessageChannelManager.PostEmail(createEmailMessage)); }
public static MailMessage ConstructContent(string address, string addressName, string subject, string message, CreateEmailMessage CreateEmailMessage = null, string BCCAddress = "") { var mailMessage = new MailMessage(); mailMessage.From = new MailAddress(ConfigHelper.GetValueFromAppSetting("SiteEmailDefault"), ConfigHelper.GetValueFromAppSetting("SiteEmailNameDefault")); mailMessage.To.Add(new MailAddress(address, string.IsNullOrEmpty(addressName) ? address : addressName)); if (BCCAddress != "" && BCCAddress.Contains(',')) { string[] bcc = BCCAddress.Split(','); foreach (string bc in bcc) { if (!string.IsNullOrEmpty(bc)) { mailMessage.Bcc.Add(new MailAddress(bc)); } } } else if (BCCAddress != "") { mailMessage.Bcc.Add(new MailAddress(BCCAddress)); } mailMessage.Subject = subject; string msgStr = message; if (msgStr == "" && CreateEmailMessage != null) { msgStr = CreateEmailMessage(); message = msgStr; } mailMessage.Body = message; mailMessage.BodyEncoding = System.Text.Encoding.UTF8; mailMessage.SubjectEncoding = System.Text.Encoding.UTF8; mailMessage.IsBodyHtml = true; return(mailMessage); }