private MailMessage CreateMessageFromViewModel(SmtpSettingsViewModel testSettings) { var message = new MailMessage(); message.To.Add(testSettings.To); foreach (var address in ParseMailAddresses(testSettings.Cc)) { message.CC.Add(address); } foreach (var address in ParseMailAddresses(testSettings.Bcc)) { message.Bcc.Add(address); } foreach (var address in ParseMailAddresses(testSettings.ReplyTo)) { message.ReplyToList.Add(address); } if (!String.IsNullOrWhiteSpace(testSettings.Subject)) { message.Subject = testSettings.Subject; } if (!String.IsNullOrWhiteSpace(testSettings.Body)) { message.Body = testSettings.Body; } return(message); }
public async Task <IActionResult> Post(SmtpSettingsViewModel model) { if (!await _authorizationService.AuthorizeAsync(User, Permissions.ManageEmailSettings)) { return(Unauthorized()); } if (ModelState.IsValid) { var message = CreateMessageFromViewModel(model); // send email with DefaultSender var result = await _smtpService.SendAsync(message); if (!result.Succeeded) { foreach (var error in result.Errors) { ModelState.AddModelError("*", error.ToString()); } } else { _notifier.Success(H["Message sent successfully"]); return(Redirect(Url.Action("Index", "Admin", new { area = "OrchardCore.Settings", groupId = SmtpSettingsDisplayDriver.GroupId }))); } } return(View(model)); }
private MailMessage CreateMessageFromViewModel(SmtpSettingsViewModel testSettings) { var message = new MailMessage { To = testSettings.To, Bcc = testSettings.Bcc, Cc = testSettings.Cc, ReplyTo = testSettings.ReplyTo }; if (!String.IsNullOrWhiteSpace(testSettings.Sender)) { message.Sender = testSettings.Sender; } if (!String.IsNullOrWhiteSpace(testSettings.Subject)) { message.Subject = testSettings.Subject; } if (!String.IsNullOrWhiteSpace(testSettings.Body)) { message.Body = testSettings.Body; } return(message); }
//[WebInvoke(Method = "POST", UriTemplate = "/smtptest/")] public string TestSmtpServer(SmtpSettingsViewModel settings) { var request = new RestRequest(this.ServiceUrl + "/smtptest/", Method.POST); request.AddParameter("application/json", SerializeObject(settings), ParameterType.RequestBody); return(ExecuteRequestFor <string>(request)); }
public ActionResult EditSmtpService(SmtpSettingsViewModel model) { var emailServiceSettings = new EmailServiceSettings(); if (ModelState.IsValid) { emailServiceSettings.IsEmailServiceEnabled = model.Enabled; emailServiceSettings.Host = model.Host; emailServiceSettings.Port = model.Port.Value; emailServiceSettings.SslEnabled = model.Ssl; emailServiceSettings.Login = model.Login; emailServiceSettings.Password = model.Password; } return(PartialView("_SmtpSettings", model)); }
public ActionResult EditSmtpService() { var emailServiceSettings = new EmailServiceSettings(); var smtpModel = new SmtpSettingsViewModel() { Enabled = emailServiceSettings.IsEmailServiceEnabled, Host = emailServiceSettings.Host, Port = emailServiceSettings.Port, Ssl = emailServiceSettings.SslEnabled, Login = emailServiceSettings.Login, }; return(PartialView("_SmtpSettings", smtpModel)); }
private MailMessage CreateMessageFromViewModel(SmtpSettingsViewModel testSettings) { var message = new MailMessage(); foreach (var email in ParseEmailAddresses(testSettings.To)) { if (ValidateEmail(email)) { message.To.Add(email); } else { ModelState.AddModelError(string.Empty, T["Invalid \"To\" email : "] + email); } } foreach (var email in ParseEmailAddresses(testSettings.Bcc)) { if (ValidateEmail(email)) { message.Bcc.Add(email); } else { ModelState.AddModelError(string.Empty, T["Invalid \"Bcc\" email : "] + email); } } foreach (var email in ParseEmailAddresses(testSettings.Cc)) { if (ValidateEmail(email)) { message.CC.Add(email); } else { ModelState.AddModelError(string.Empty, T["Invalid \"Cc\" email : "] + email); } } foreach (var email in ParseEmailAddresses(testSettings.ReplyTo)) { if (ValidateEmail(email)) { message.ReplyToList.Add(email); } else { ModelState.AddModelError(string.Empty, T["Invalid \"Reply To\" email : "] + email); } } if (!String.IsNullOrWhiteSpace(testSettings.Subject)) { message.Subject = testSettings.Subject; } if (!String.IsNullOrWhiteSpace(testSettings.Body)) { message.Body = testSettings.Body; } return(message); }