public async Task <IActionResult> OnPostAsync() { if (ModelState.IsValid) { var user = await _userManager.FindByEmailAsync(Input.Email); if (user is null || !await _userManager.IsEmailConfirmedAsync(user)) { return(Page()); } var code = await _userManager.GeneratePasswordResetTokenAsync(user); code = WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(code)); var callbackUrl = Url.Page( "/Account/ResetPassword", pageHandler: null, values: new { area = "Identity", code }, // TODO: ?. protocol: HttpContext.Request.Scheme); // Remove the mandatory check by mail during debugging. #if RELEASE var email = _emailTemplate.GetTemplate(EmailMessageType.ForgotPasswordConfirmation, callbackUrl); await _emailSender.SendEmailAsync(Input.Email, email.subject, email.template); return(RedirectToPage("./ForgotPasswordConfirmation")); #elif DEBUG return(Redirect(callbackUrl)); #endif } return(Page()); }
public Task <Unit> Handle(SendEmailCommand request, CancellationToken cancellationToken) { string content = _emailTemplate.GetTemplate("application") .Replace("{Name}", request.Name) .Replace("{Phone}", request.Phone) .Replace("{Time}", _dateTime.Now.ToString("MM/dd/yyyy hh:mm tt")); _emailSender.Send(content, "Заявка с сайта", _emailSender.GetMail()); return(Unit.Task); }
private void SendReminderMail(int countDays) { var model = _userInfoRepository.GetDataFromUsersByConcreteDay(countDays); var template = _template.GetTemplate(REMINDER_MAIL_VIEW); foreach (var user in model) { var body = _compiler.Compile(template, REMINDER_MAIL_VIEW, new UserEmail { Name = user.Name, LeftDays = countDays }); _sendEmail.Send(user.To, SUBJECT_RECURRINGJOB, body); } }
public async Task <IActionResult> OnPostAsync(string returnUrl = null) { returnUrl ??= Url.Content("~/"); if (ModelState.IsValid) { var _user = await _userManager.FindByNameAsync(Input.UserName); if (_user != null) { ModelState.AddModelError("Input.UserName", _localizer["LoginExist"]); return(Page()); } _user = await _userManager.FindByEmailAsync(Input.Email); if (_user != null) { ModelState.AddModelError(string.Empty, _localizer["EmailExist"]); return(Page()); } string[] fullName = Input.FullName.Split(' '); ApplicationUser user = new() { Email = Input.Email, UserName = Input.UserName, Name = fullName[1], Surname = fullName[0], MiddleName = fullName[2], UniqueUrl = _urlGenerator.Generate(), RegistrationDate = DateTime.UtcNow }; var result = await _userManager.CreateAsync(user, Input.Password); if (result.Succeeded) { _logger.LogInformation($"New User {user.Id} registered"); await _userManager.AddToRoleAsync(user, "User"); // Remove the mandatory check by mail during debugging. #if DEBUG return(RedirectToPage("./Login")); #elif RELEASE var code = await _userManager.GenerateEmailConfirmationTokenAsync(user); code = WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(code)); var callbackUrl = Url.Page("/Account/ConfirmEmail", pageHandler: null, values: new { area = "Identity", userId = user.Id, code = code }, protocol: Request.Scheme); var email = _emailTemplate.GetTemplate(EmailMessageType.RegisterConfirmation, callbackUrl); await _emailSender.SendEmailAsync(Input.Email, email.subject, email.template); return(RedirectToPage("./RegisterConfirmation")); #endif } foreach (var error in result.Errors) { ModelState.AddModelError(string.Empty, error.Description); } } return(Page()); } }
public void SendEmail(string recipient, IEmailTemplate template) { var smtpSettings = configuration.GetSection("Smtp"); var smtpClient = new SmtpClient(smtpSettings["Host"], int.Parse(smtpSettings["Port"])); smtpClient.Credentials = new NetworkCredential(smtpSettings["SystemEmail"], Environment.GetEnvironmentVariable("SwimmingPoolSmtpHostPassword", EnvironmentVariableTarget.Machine)); smtpClient.UseDefaultCredentials = true; smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network; smtpClient.EnableSsl = true; var mail = new MailMessage { From = new MailAddress(smtpSettings["SystemEmail"], smtpSettings["SystemSenderName"]), Body = template.GetTemplate() }; mail.To.Add(new MailAddress(recipient)); smtpClient.Send(mail); }