我正在使用以下代码尝试异步发送电子邮件,但没有发送电子邮件,并且我不确定哪里做错了。我还在 web.config 中添加了电子邮件协议的第二段代码。
发送电子邮件异步代码
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);
在您的应用程序中,您可能有一个名为IdentityConfig.cs
in the App_Start
文件夹。该文件的顶部可能有这样的内容:
public class EmailService : IIdentityMessageService
{
public Task SendAsync(IdentityMessage message)
{
// Plug in your email service here to send an email.
return Task.FromResult(0);
}
}
将其更改为:
public class EmailService : IIdentityMessageService
{
public Task SendAsync(IdentityMessage message)
{
SmtpClient client = new SmtpClient();
return client.SendMailAsync(ConfigurationManager.AppSettings["SupportEmailAddr"],
message.Destination,
message.Subject,
message.Body);
}
}
根据您的喜好自定义发送代码。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)