c# – UserManager SendEmailAsync没有发送电子邮件

我正在使用以下代码尝试异步发送电子邮件,但没有发送电子邮件,我不知道正在做什么错误.我还在电子邮件协议的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);
在您的应用程序中,您可能在App_Start文件夹中有一个名为IdentityConfig.cs的文件.该文件可能有这样的顶部:

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);
    }
}

根据您的喜好定制发送代码.

翻译自:https://stackoverflow.com/questions/31523276/usermanager-sendemailasync-no-email-sent

转载注明原文:c# – UserManager SendEmailAsync没有发送电子邮件