public string Insert(AdminUserViewModel model, IUrlHelper url, string scheme) { var existing = userManager.FindByEmailAsync(model.Email).GetAwaiter().GetResult(); if (existing != null) { return(null); } var user = mapper.Map <GLAAUser>(model); userManager.CreateAsync(user).GetAwaiter().GetResult(); userManager.AddToRoleAsync(user, model.Role).GetAwaiter().GetResult(); // For more information on how to enable account confirmation and password reset please // visit https://go.microsoft.com/fwlink/?LinkID=532713 var code = userManager.GeneratePasswordResetTokenAsync(user).GetAwaiter().GetResult(); var callbackUrl = url.Action("ResetPassword", "AccountController", new { userId = user.Id, code = code }, scheme); var msg = new NotifyMailMessage(model.Email, new Dictionary <string, dynamic> { { "full_name", user.FullName ?? "User" }, { "reset_password_link", callbackUrl } }); var template = configuration.GetSection("GOVNotify:EmailTemplates")["ResetPassword"]; var success = emailService.Send(msg, template); return(user.Id); }
public async Task ExecuteAsync(CancellationToken cancellationToken) { logger.TimedLog(LogLevel.Information, $"Task Started: Send Test Email"); var msg = new NotifyMailMessage("*****@*****.**", new Dictionary <string, dynamic> { { "full_name", "Doug" }, { "confirm_email_link", "na" } }); var template = configuration.GetSection("GOVNotify:EmailTemplates")["ConfirmEmail"]; var success = emailService.Send(msg, template); var successMessage = success ? "SUCCESS" : "FAILED"; logger.TimedLog(LogLevel.Information, $"Task Completed: Send Test Email : {successMessage}"); }
public bool Send(NotifyMailMessage msg, string messageTemplate) { try { client.SendEmail( msg.To, messageTemplate, msg.Personalisation, null, null); logger.TimedLog(LogLevel.Information, $"Email sent to GOV.Notify : Address : {msg.To} : Success"); return(true); } catch (NotifyClientException ex) { logger.TimedLog(LogLevel.Error, $"Email sending to GOV.Notify FAILED : Message: {ex.Message}", ex); return(false); } }
public async Task SendConfirmationAsync(string email, IUrlHelper url) { if (string.IsNullOrEmpty(email) || url == null) { return; } var user = await userManager.FindByEmailAsync(email); var token = await userManager.GenerateEmailConfirmationTokenAsync(user); var callbackUrl = url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = token }); var msg = new NotifyMailMessage(email, new Dictionary <string, dynamic> { { "full_name", user.FullName ?? "User" }, { "confirm_email_link", callbackUrl } }); var template = configuration.GetSection("GOVNotify:EmailTemplates")["ConfirmEmail"]; emailService.Send(msg, template); }
public async Task <IActionResult> ForgotPassword(ForgotPasswordViewModel model) { if (ModelState.IsValid) { var user = await _userManager.FindByEmailAsync(model.Email); TempData["Email"] = model.Email; //TODO: do we need users to confirm accounts //|| !(await _userManager.IsEmailConfirmedAsync(user)) if (user == null) { // Don't reveal that the user does not exist or is not confirmed return(RedirectToAction(nameof(ForgotPasswordConfirmation))); } // For more information on how to enable account confirmation and password reset please // visit https://go.microsoft.com/fwlink/?LinkID=532713 var code = await _userManager.GeneratePasswordResetTokenAsync(user); var callbackUrl = Url.ResetPasswordCallbackLink(user.Id, code, Request.Scheme); var msg = new NotifyMailMessage(model.Email, new Dictionary <string, dynamic> { { "full_name", user.FullName ?? "User" }, { "reset_password_link", callbackUrl } }); var template = configuration.GetSection("GOVNotify:EmailTemplates")["ResetPassword"]; var success = emailService.Send(msg, template); return(RedirectToAction(nameof(ForgotPasswordConfirmation))); } return(View(model)); }
public bool SendEmail(NotifyMailMessage msg, string template) { return(emailService.Send(msg, template)); }