C# 我放弃的密码方法不是发送电子邮件
我有一个问题,在我的忘记密码方法,虽然它的状态=RANTO完成,但没有收到任何电子邮件。我尝试了许多电子邮件地址,但什么都没有。谁能告诉我可能有什么问题吗。 代码如下:C# 我放弃的密码方法不是发送电子邮件,c#,asp.net-mvc,C#,Asp.net Mvc,我有一个问题,在我的忘记密码方法,虽然它的状态=RANTO完成,但没有收到任何电子邮件。我尝试了许多电子邮件地址,但什么都没有。谁能告诉我可能有什么问题吗。 代码如下: // POST: /Account/ForgotPassword [HttpPost] [AllowAnonymous] [ValidateAntiForgeryToken] public async Task<ActionResult> Forg
// 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 that the user does not exist or is 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 your password by clicking <a href=\"" + callbackUrl + "\">here</a>");
return RedirectToAction("ForgotPasswordConfirmation", "Account");
}
// If we got this far, something failed, redisplay form
return View(model);
}
//POST:/Account/放弃密码
[HttpPost]
[异名]
[ValidateAntiForgeryToken]
公共异步任务);
返回重定向操作(“放弃密码确认”、“帐户”);
}
//如果我们走到这一步,有些东西失败了,重新显示形式
返回视图(模型);
}
这是我的调试图像:
那么,您是否使用正确的smtp服务器设置配置了Web.Config?请参阅以下讨论: 您需要设置的是:
<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>
之后,尝试更改此行:
await UserManager.SendEmailAsync(user.Id, "Reset Password", "Please reset your password by clicking <a href=\"" + callbackUrl + "\">here</a>");
wait UserManager.sendmailasync(user.Id,“重置密码”,“请通过单击重置密码”);
为此:
UserManager.SendEmail(user.Id, "Reset Password", "Please reset your password by clicking <a href=\"" + callbackUrl + "\">here</a>");
UserManager.sendmail(user.Id,“重置密码”,“请通过单击重置密码”);
注意没有
Async
和wait
,然后尝试调试应用程序,如果出现任何错误,您应该能够看到堆栈跟踪。那么,您是否使用正确的smtp服务器设置配置了Web.Config?请参阅本讨论:
您需要设置的是:
<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>
之后,尝试更改此行:
await UserManager.SendEmailAsync(user.Id, "Reset Password", "Please reset your password by clicking <a href=\"" + callbackUrl + "\">here</a>");
wait UserManager.sendmailasync(user.Id,“重置密码”,“请通过单击重置密码”);
为此:
UserManager.SendEmail(user.Id, "Reset Password", "Please reset your password by clicking <a href=\"" + callbackUrl + "\">here</a>");
UserManager.sendmail(user.Id,“重置密码”,“请通过单击重置密码”);
请注意没有
Async
和wait
,然后尝试调试应用程序,如果出现任何错误,您应该能够看到堆栈跟踪。如何配置电子邮件设置?您使用的smtp服务器是什么?为了进行故障排除,请尝试UserManager.sendmail(
而不是异步版本…这样更容易调试。很抱歉,我刚刚接触asp.net,我不知道如何知道。请告诉我。如何配置电子邮件设置?使用哪种smtp服务器?为了排除故障,请尝试UserManager.sendmail(
而不是异步版本…这样更容易调试。很抱歉,我刚刚接触asp.net,不知道如何知道。请告诉我。