gpt4 book ai didi

c# - UserManager SendEmailAsync 未发送电子邮件

转载 作者:IT王子 更新时间:2023-10-29 04:20:23 30 4
gpt4 key购买 nike

我正在使用以下代码尝试异步发送电子邮件,但没有发送任何电子邮件,我不确定哪里做错了。我还在 web.config 中为电子邮件协议(protocol)添加了第二段代码。

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

根据您的喜好自定义发送代码。

关于c# - UserManager SendEmailAsync 未发送电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31523276/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com