public ActionResult MailSend(MailSendViewModel model) { var result = SendMail(model); if (result) { return(RedirectToAction("CommentList")); } else { return(View()); } }
public async Task <ActionResult> MailSend(string id) { MailSendViewModel model = new MailSendViewModel(); var user = await UserManager.FindByIdAsync(id); if (user != null) { model.UserName = user.UserName; model.Email = user.Email; return(View(model)); } else { return(RedirectToAction("CommentList")); } }
public async Task <IActionResult> MailSend(int id) { try { var user = await _userService.GetDetails(id); SetPageTitle(user, "Send Mail"); MailSendViewModel viewModel = new MailSendViewModel() { Id = user.Id }; return(View(viewModel)); } catch (GraException gex) { ShowAlertWarning("Unable to view participant's mail: ", gex); return(RedirectToAction("Index")); } }
public bool SendMail(MailSendViewModel model) { try { string senderMail = System.Configuration.ConfigurationManager.AppSettings["senderMail"].ToString(); string senderPassword = System.Configuration.ConfigurationManager.AppSettings["senderPassword"].ToString(); SmtpClient client = new SmtpClient("smtp.gmail.com", 587); client.EnableSsl = true; client.Timeout = 100000; client.DeliveryMethod = SmtpDeliveryMethod.Network; client.UseDefaultCredentials = false; client.Credentials = new NetworkCredential(senderMail.Trim(), senderPassword.Trim()); MailMessage mailMessage = new MailMessage(senderMail, model.Email, model.Subject, model.BodyText); mailMessage.IsBodyHtml = true; mailMessage.BodyEncoding = UTF8Encoding.UTF8; client.Send(mailMessage); return(true); } catch (Exception ex) { return(false); } }
public async Task <IActionResult> MailSend(MailSendViewModel model) { if (ModelState.IsValid) { Mail mail = new Mail() { ToUserId = model.Id, Subject = model.Subject, Body = model.Body, }; await _mailService.MCSendAsync(mail); AlertSuccess = "Mail sent to participant"; return(RedirectToAction("Mail", new { id = model.Id })); } else { var user = await _userService.GetDetails(model.Id); SetPageTitle(user, "Send Mail"); return(View()); } }