protected async Task <IActionResult> SendMessageAsync(EmailModel model, IEmailClientConfiguration config = null) { if (config == null) { config = await _emailClientSettingsFactory.GetConfigurationAsync(); } _emailClient.Configuration = config; return(await this.SendEmailAsync(model, _emailClient)); }
/// <summary> /// Performs internal one-time initializations. /// </summary> /// <returns></returns> protected virtual async Task InitAsync() { if (_initialized) { return; } Client.Configuration = await _configProvider.GetConfigurationAsync(); _initialized = true; }
public async Task <IActionResult> ForgotPassword([FromBody] ForgotPasswordModel fpm) { try { var user = await UserManager.FindByNameAsync(fpm.UserName); if (user != null) { if (!user.Disabled) { var locale = System.Threading.Thread.CurrentThread.CurrentUICulture.Name; // the localized e-mail template name var viewName = string.Format(EMAIL_TEMPLATE, $".{locale}"); // check if the physical file path of the template exists var path = _hostingEnvironment.ContentRootPath.TrimEnd(DirSeparator) + viewName.Replace('/', DirSeparator); if (!System.IO.File.Exists(path)) { // get the default email template viewName = string.Format(EMAIL_TEMPLATE, ".fr"); } var config = Startup.InternalConfiguration; var model = new ResetPasswordViewModel { UserName = fpm.UserName, AppName = config["ApplicationName"], Token = await UserManager.GeneratePasswordResetTokenAsync(user), BaseUrl = config.GetSection(nameof(JwtIssuerOptions))[nameof(JwtIssuerOptions.Audience)], }; // render the email template var body = await _templateViewRender.RenderToStringAsync(viewName, model); // create the message. var email = new EmailModel { Body = body, Subject = ResetYourPassword, From = Services.Emails.EmailDispatcher.Instance.EmailSettings.Outgoing.FromDisplay, To = user.Email, }; // get e-mail client config and send it _emailClient.Configuration = await _emailClientSettingsFactory.GetConfigurationAsync(); return(await this.SendEmailAsync(email, _emailClient)); } else { // account disabled return(BadRequest(ModelState.AddError(string.Empty, UserAccountDoesNotExistOrDisabled))); } } else { // for security reasons never reveal the account does not exist return(BadRequest(ModelState.AddError(string.Empty, UserAccountDoesNotExistOrDisabled))); } } catch (System.Exception ex) { return(BadRequest(ex)); } }