I am sending an email to the user who forgot their password, the email can now be sent, but I would like to add a personalized template. I do not know if it would be possible to pass the view .cshtml as a body parameter to the email.
I already have a defined .cshtml template, and I think that if I included the html code in the controller it would not look good, because it would be many lines of code.
// POST: /Account/ForgotPassword
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public async Task<ActionResult> ForgotPassword(ForgotPasswordViewModel model)
{
//Verify Email
//Generate Reset Password link
//Send Email
if (ModelState.IsValid)
{
var user = await UserManager.FindByNameAsync(model.Email);
// if (user == null || !(await UserManager.IsEmailConfirmedAsync(user.Id)))
if (user == null)
{
ModelState.AddModelError("", "El correo es invalido");
// Don't reveal that the user does not exist or is not confirmed
return View("ForgotPasswordConfirmation");
}
var emailService = new EmailService();
string code = await UserManager.GeneratePasswordResetTokenAsync(user.Id);
var callbackUrl = Url.Action("ResetPassword", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
string Body = "Please reset your password by clicking <a href=\"" + callbackUrl + "\">here</a>";
await UserManager.SendEmailAsync(user.Id, "Reset Password", Body );
return RedirectToAction("ForgotPasswordConfirmation", "Account");
}
// If we got this far, something failed, redisplay form
return View(model);
}
in this line we send as parameter the body of the email
string Body="Please reset your password by clicking here";
await UserManager.SendEmailAsync (user.Id, "Reset Password", Body);
I hope your help. Thank you very much :)