c# - My ForgotPassword method is not sending email -
i have problem in forgot password method although status=rantocompletion there no email received @ all. i've tried many email addresses , there nothing. can 1 tell me might problem. here code:
// post: /account/forgotpassword [httppost] [allowanonymous] [validateantiforgerytoken] public async task<actionresult> forgotpassword(forgotpasswordviewmodel model) { if (modelstate.isvalid) { var user = await usermanager.findbynameasync(model.email); if (user == null || !(await usermanager.isemailconfirmedasync(user.id))) { // don't reveal user not exist or not confirmed return view("forgotpasswordconfirmation"); } 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", "please reset password clicking <a href=\"" + callbackurl + "\">here</a>"); return redirecttoaction("forgotpasswordconfirmation", "account"); } // if got far, failed, redisplay form return view(model); }
and here debugging image:
well, have configure web.config proper smtp server settings? refer discussion: gmail + c# + web.config: send mail works programmatically, throws exception using web.config values
what need set this:
<system.net> <mailsettings> <smtp deliverymethod="network" from="your@emailaddress.com"> <network host="smtp.gmail.com" port="587" defaultcredentials="true" username="your@emailaddress.com" password="somepassword" /> </smtp> </mailsettings> </system.net>
after that, try changing line:
await usermanager.sendemailasync(user.id, "reset password", "please reset password clicking <a href=\"" + callbackurl + "\">here</a>");
to this:
usermanager.sendemail(user.id, "reset password", "please reset password clicking <a href=\"" + callbackurl + "\">here</a>");
note absence of async
, await
, , try debug application, should able see stacktrace should wrong happens.
Comments
Post a Comment