【发布时间】:2015-07-20 18:00:39
【问题描述】:
我正在使用以下代码尝试异步发送电子邮件,但没有发送电子邮件,并且我不确定哪些操作不正确。我还在 web.config 中为电子邮件协议添加了第二段代码。
SendEmailAsync 代码
await UserManager.SendEmailAsync(username.Id, "MTSS-B: Forgot Password", "Here is your new password. Please go back to the MTSS-B web tool and sign in. You will be prompted to create your own password.<br/><br/>" + tmpPass + "<br/><br/>MTSS-B Administrator");
Web.config 代码
<system.net>
<mailSettings>
<smtp>
<network host="smtp1.airws.org" userName="" password="" />
</smtp>
</mailSettings>
</system.net>
****更新****
我测试了是否可以使用常规方法发送电子邮件,并且可以使用以下代码发送电子邮件。
MailMessage m = new MailMessage(new MailAddress(ConfigurationManager.AppSettings["SupportEmailAddr"]), new MailAddress(model.Email));
m.Subject = "MTSS-B: Forgot Password";
m.Body = string.Format("Here is your new password. Please go back to the MTSS-B web tool and sign in. You will be prompted to create your own password.<br/><br/>Password: " + tmpPass + "<br/><br/>MTSS-B Administrator");
m.IsBodyHtml = true;
SmtpClient smtp = new SmtpClient("smtp2.airws.org");
smtp.Send(m);
【问题讨论】:
-
您需要在web.config文件中有一个有效的用户名和密码
-
我们不需要用户名和密码来访问我们的网络主机。这已在其他应用程序中以相同的方式实现。
-
你有端口号吗?如果端口号不是问题,请尝试使用非异步 SendEmail 功能来测试它是否出错。
-
好的,我试试非异步发送邮件功能。
-
我可以使用 system.net.mail 发送电子邮件,所以我不确定为什么我无法使用 sendemailasync 发送电子邮件。
标签: c# asp.net-mvc