public ActionResult SendEmail(Email email) { StringBuilder errorStringBuilder = new StringBuilder(); var emailViewModel = new Email(); if (email.Subject == null) { errorStringBuilder.AppendLine("Subject cannot be empty"); } if (email.MessageBody == null) { errorStringBuilder.AppendLine("\nEmail Body cannot be empty"); } if (errorStringBuilder.ToString() != "") { ViewBag.ErrorMessage = errorStringBuilder.ToString(); } else { ViewBag.ErrorMessage = ""; } try { if( ViewBag.ErrorMessage == "") SendEmailToProvider(email); emailViewModel.Providers = new DrodownItemsViewModel(); emailViewModel.Providers.Items = GetProvidersToSendEmail(); } catch (Exception ex) { ViewBag.ErrorMessage = ex.Message; } if (ViewBag.ErrorMessage == "") ViewBag.SuccessMessage = "Email sent successfully!"; return View(emailViewModel); }
private void SendEmailToProvider(Email emailModel) { var fromEmailAddress = new PatientRepository().GetEmailAddress(int.Parse(Session["PatientId"].ToString())); var smptSendGrid = new SMTPApi(fromEmailAddress, new List<string>{ emailModel.Providers.SelectedItemId }); smptSendGrid.SimpleEmail(emailModel.Subject, emailModel.MessageBody); }
public ActionResult SendEmail() { if (Session["PatientId"] == null || Session["PatientId"].ToString() == "") { return RedirectToAction("Login", "Account"); } var emailViewModel = new Email(); emailViewModel.Providers = new DrodownItemsViewModel(); emailViewModel.Providers.Items = GetProvidersToSendEmail(); return View(emailViewModel); }