You must Sign In to post a response.
  • Category: ASP.Net MVC

    Unable to send mail using form based authentication

    i am unable to send mail using below code when call await UserManager.SendEmailAsync()

    [HttpPost]
    [AllowAnonymous]
    [ValidateAntiForgeryToken]
    public async Task<ActionResult> ForgotPassword(ForgotPasswordViewModel model)
    {
    if (ModelState.IsValid)
    {
    var user = await UserManager.FindByNameAsync(model.Email);
    // Don't check confirmation status for now
    //if (user == null || !(await UserManager.IsEmailConfirmedAsync(user.Id)))
    if (user == null)
    {
    ModelState.AddModelError("", "The user either does not exist or is not confirmed.");
    return View();
    }

    // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771
    // Send an email with this link
    string code = await UserManager.GeneratePasswordResetTokenAsync(user.Id);
    var callbackUrl = Url.Action("ResetPassword", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
    try
    {
    await UserManager.SendEmailAsync(user.Id, "Reset Password", "Please reset your password by clicking <a href=\"" + callbackUrl + "\">here</a>");
    }
    catch (Exception ex)
    {
    ModelState.AddModelError("", ex.Message);
    return View(model);
    }
    return RedirectToAction("ForgotPasswordConfirmation", "Account");
    }

    // If we got this far, something failed, redisplay form
    return View(model);
    }


    provide some code to send mail when call await UserManager.SendEmailAsync()
  • #762259
    Hello Sandip,

    You can go through the below links for your reference :

    http://www.codeproject.com/Articles/712485/Send-Email-to-Selected-Recipients-from-your-ASP-NE

    http://www.c-sharpcorner.com/UploadFile/sourabh_mishra1/sending-an-e-mail-using-Asp-Net-mvc/

    https://msdn.microsoft.com/en-us/library/ff398049(v=vs.100).aspx


    Hope this will work for you.

    Regards,
    Nirav Lalan
    DNS Gold Member
    "Failure is the path of least persistence"


Sign In to post your comments