I am having this code to send e-mail to reset user password:
//
// POST: /Account/ForgotPassword
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public async Task<JsonResult> ForgotPassword(ForgotPasswordViewModel model, bool CaptchaValid)
{
string mensaje = String.Empty;
if (ModelState.IsValid)
{
if (!CaptchaValid)
mensaje = "ERROR: Captcha inválido.";
else
{
var user = await UserManager.FindByEmailAsync(model.Email);
if (user == null || !(await UserManager.IsEmailConfirmedAsync(user.Id)))
{
mensaje = "ERROR: La dirección de correo electrónico no está registrada.";
}
else
{
var provider = new DpapiDataProtectionProvider("WebAttendance");
UserManager.UserTokenProvider = new DataProtectorTokenProvider<ApplicationUser, string>(provider.Create("UserToken")) as IUserTokenProvider<ApplicationUser, string>;
string code = await UserManager.GeneratePasswordResetTokenAsync(user.Id);
var callbackUrl = Url.Action("ResetPassword", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
await UserManager.SendEmailAsync(user.Id, "Reset Password", "Por favor, cambie su contraseña al hacer click <a href=\"" + callbackUrl + "\">aquí</a>");
return Json("INFO: Se envió un mail a su cuenta de correo con instrucciones para cambiar su contraseña.");
}
}
}
// If we got this far, something failed, redisplay form
return Json(mensaje);
}
The above code runs without any error, but e-mail is not actually sent.
This is the Web.config entries:
<system.net>
<mailSettings>
<smtp from="info@xxx.com">
<network host="mail.desytec.cl" password="xxxx" port="587" userName="yyy@xxx.cl" enableSsl="false"/>
</smtp>
</mailSettings>
</system.net>
By the way, when reading some posts, I knew that I have to have IdentityConfig.cs file in App_Start, but that file is missing. May this be the cause?