public ActionResult IndexPOST() { if (!_orchardServices.Authorizer.Authorize(StandardPermissions.SiteOwner, T("Not allowed to upgrade."))) return new HttpUnauthorizedResult(); var activityTable = _upgradeService.GetPrefixedTableName("Orchard_Workflows_ActivityRecord"); if (_upgradeService.TableExists(activityTable)) { _upgradeService.ExecuteReader("SELECT * FROM " + activityTable + " WHERE Name = 'SendEmail'", (reader, connection) => { var record = _repository.Get((int)reader["Id"]); if (record == null) { return; } var state = JsonConvert.DeserializeAnonymousType(record.State, new { Body = "", Subject = "", Recipient = "", RecipientOther = "", }); var newState = new EmailMessage { Body = state.Body, Subject = state.Subject }; if (!newState.Body.StartsWith("<p ")) { newState.Body = newState.Body + System.Environment.NewLine; } if (state.Recipient == "owner") { newState.Recipients = "{Content.Author.Email}"; } else if (state.Recipient == "author") { newState.Recipients = "{User.Current.Email}"; } else if (state.Recipient == "admin") { newState.Recipients = "{Site.SuperUser.Email}"; } else if (state.Recipient == "other") { newState.Recipients = state.RecipientOther; } record.State = JsonConvert.SerializeObject(newState); }); _orchardServices.Notifier.Information(T("Email activities updated successfully")); } else { _orchardServices.Notifier.Warning(T("No email activities were updated.")); } return RedirectToAction("Index"); }
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 {}; 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"); } }
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"); } }