public void Process(IDictionary <string, object> parameters) { if (!_smtpSettings.IsValid()) { return; } var emailMessage = new EmailMessage { Body = parameters["Body"] as string, Subject = parameters["Subject"] as string, Recipients = parameters["Recipients"] as string }; if (emailMessage.Recipients.Length == 0) { Logger.Error("Email message doesn't have any recipient"); return; } // Applying default Body alteration for SmtpChannel var template = _shapeFactory.Create("Template_Smtp_Wrapper", Arguments.From(new { Content = new MvcHtmlString(emailMessage.Body) })); var mailMessage = new MailMessage { Subject = emailMessage.Subject, Body = _shapeDisplay.Display(template), IsBodyHtml = true }; var section = (SmtpSection)ConfigurationManager.GetSection("system.net/mailSettings/smtp"); mailMessage.From = !String.IsNullOrWhiteSpace(_smtpSettings.Address) ? new MailAddress(_smtpSettings.Address) : new MailAddress(section.From); try { foreach (var recipient in emailMessage.Recipients.Split(new [] { ',', ';' }, StringSplitOptions.RemoveEmptyEntries)) { mailMessage.To.Add(new MailAddress(recipient)); } _smtpClientField.Value.Send(mailMessage); } catch (Exception e) { Logger.Error(e, "Could not send email"); } }
public void Process(IDictionary <string, object> parameters) { if (!_smtpSettings.IsValid()) { return; } var emailMessage = new EmailMessage { Body = Read(parameters, "Body"), Subject = Read(parameters, "Subject"), Recipients = Read(parameters, "Recipients"), ReplyTo = Read(parameters, "ReplyTo"), From = Read(parameters, "From"), Bcc = Read(parameters, "Bcc"), Cc = Read(parameters, "CC") }; if (emailMessage.Recipients.Length == 0) { Logger.Error("Email message doesn't have any recipient"); return; } // Apply default Body alteration for SmtpChannel. var template = _shapeFactory.Create("Template_Smtp_Wrapper", Arguments.From(new { Content = new MvcHtmlString(emailMessage.Body) })); var mailMessage = new MailMessage { Subject = emailMessage.Subject, Body = _shapeDisplay.Display(template), IsBodyHtml = true }; if (parameters.ContainsKey("Message")) { // A full message object is provided by the sender. var oldMessage = mailMessage; mailMessage = (MailMessage)parameters["Message"]; if (String.IsNullOrWhiteSpace(mailMessage.Subject)) { mailMessage.Subject = oldMessage.Subject; } if (String.IsNullOrWhiteSpace(mailMessage.Body)) { mailMessage.Body = oldMessage.Body; mailMessage.IsBodyHtml = oldMessage.IsBodyHtml; } } try { foreach (var recipient in ParseRecipients(emailMessage.Recipients)) { mailMessage.To.Add(new MailAddress(recipient)); } if (!String.IsNullOrWhiteSpace(emailMessage.Cc)) { foreach (var recipient in ParseRecipients(emailMessage.Cc)) { mailMessage.CC.Add(new MailAddress(recipient)); } } if (!String.IsNullOrWhiteSpace(emailMessage.Bcc)) { foreach (var recipient in ParseRecipients(emailMessage.Bcc)) { mailMessage.Bcc.Add(new MailAddress(recipient)); } } if (!String.IsNullOrWhiteSpace(emailMessage.From)) { mailMessage.From = new MailAddress(emailMessage.From); } else { // Take 'From' address from site settings or web.config. mailMessage.From = !String.IsNullOrWhiteSpace(_smtpSettings.Address) ? new MailAddress(_smtpSettings.Address) : new MailAddress(((SmtpSection)ConfigurationManager.GetSection("system.net/mailSettings/smtp")).From); } if (!String.IsNullOrWhiteSpace(emailMessage.ReplyTo)) { foreach (var recipient in ParseRecipients(emailMessage.ReplyTo)) { mailMessage.ReplyToList.Add(new MailAddress(recipient)); } } _smtpClientField.Value.Send(mailMessage); } catch (Exception e) { Logger.Error(e, "Could not send email"); } }
public void Process(IDictionary <string, object> parameters) { if (!_smtpSettings.IsValid()) { return; } var emailMessage = new EmailMessage { Body = Read(parameters, "Body"), Subject = Read(parameters, "Subject"), Recipients = Read(parameters, "Recipients"), ReplyTo = Read(parameters, "ReplyTo"), From = Read(parameters, "From"), Bcc = Read(parameters, "Bcc"), Cc = Read(parameters, "CC") }; if (emailMessage.Recipients.Length == 0) { Logger.Error("Email message doesn't have any recipient"); return; } var mailMessage = new MailMessage { Subject = emailMessage.Subject, Body = System.Web.HttpUtility.HtmlDecode(_shapeDisplay.Display(emailMessage.Body)), IsBodyHtml = true }; if (parameters.ContainsKey("Message")) { // A full message object is provided by the sender. var oldMessage = mailMessage; mailMessage = (MailMessage)parameters["Message"]; if (String.IsNullOrWhiteSpace(mailMessage.Subject)) { mailMessage.Subject = oldMessage.Subject; } if (String.IsNullOrWhiteSpace(mailMessage.Body)) { mailMessage.Body = oldMessage.Body; mailMessage.IsBodyHtml = oldMessage.IsBodyHtml; } } try { foreach (var recipient in ParseRecipients(emailMessage.Recipients)) { mailMessage.To.Add(new MailAddress(recipient)); } if (!String.IsNullOrWhiteSpace(emailMessage.Cc)) { foreach (var recipient in ParseRecipients(emailMessage.Cc)) { mailMessage.CC.Add(new MailAddress(recipient)); } } if (!String.IsNullOrWhiteSpace(emailMessage.Bcc)) { foreach (var recipient in ParseRecipients(emailMessage.Bcc)) { mailMessage.Bcc.Add(new MailAddress(recipient)); } } if (!String.IsNullOrWhiteSpace(emailMessage.From)) { mailMessage.From = new MailAddress(emailMessage.From); } else { // Take 'From' address from site settings or web.config. mailMessage.From = !String.IsNullOrWhiteSpace(_smtpSettings.Address) ? new MailAddress(_smtpSettings.Address) : new MailAddress(((SmtpSection)ConfigurationManager.GetSection("system.net/mailSettings/smtp")).From); } if (!String.IsNullOrWhiteSpace(emailMessage.ReplyTo)) { foreach (var recipient in ParseRecipients(emailMessage.ReplyTo)) { mailMessage.ReplyToList.Add(new MailAddress(recipient)); } } _smtpClientField.Value.Send(mailMessage); } catch (Exception e) { Logger.Error(e, "Could not send email"); if (RaiseExceptionForFailedMessages) { parameters.Add("ERROR", e); throw new OrchardException(T("Error in sending email"), e); } } }
public void Process(IDictionary <string, object> parameters) { if (!_smtpSettings.IsValid()) { return; } var emailMessage = new EmailMessage { }; object temp; if (parameters.TryGetValue("Body", out temp)) { emailMessage.Body = temp as string; } if (parameters.TryGetValue("Subject", out temp)) { emailMessage.Subject = temp as string; } if (parameters.TryGetValue("Recipients", out temp)) { emailMessage.Recipients = temp as string; } if (parameters.TryGetValue("From", out temp)) { emailMessage.From = temp as string; } if (parameters.TryGetValue("FromName", out temp)) { emailMessage.FromName = temp as string; } if (parameters.TryGetValue("HideRecipients", out temp)) { emailMessage.HideRecipients = temp as bool?; } if (emailMessage.Recipients.Length == 0) { Logger.Error("Email message doesn't have any recipient"); return; } // Applying default Body alteration for SmtpChannel var template = _shapeFactory.Create("Template_Smtp_Wrapper", Arguments.From(new { Content = new MvcHtmlString(emailMessage.Body) })); var mailMessage = new MailMessage { Subject = emailMessage.Subject, Body = _shapeDisplay.Display(template), IsBodyHtml = true }; var section = (SmtpSection)ConfigurationManager.GetSection("system.net/mailSettings/smtp"); mailMessage.From = (!String.IsNullOrWhiteSpace(emailMessage.From) ? new MailAddress(emailMessage.From, string.IsNullOrWhiteSpace(emailMessage.FromName) ? emailMessage.From : emailMessage.FromName) : null) ?? (!String.IsNullOrWhiteSpace(_smtpSettings.Address) ? new MailAddress(_smtpSettings.Address) : new MailAddress(section.From)); try { var isBCC = (emailMessage.HideRecipients.HasValue && emailMessage.HideRecipients.Value); foreach (var recipient in emailMessage.Recipients.Split(new [] { ',', ';' }, StringSplitOptions.RemoveEmptyEntries)) { if (isBCC) { mailMessage.Bcc.Add(new MailAddress(recipient)); } else { mailMessage.To.Add(new MailAddress(recipient)); } } _smtpClientField.Value.Send(mailMessage); } catch (Exception e) { Logger.Error(e, "Could not send email"); } }