本文介绍了的UserManager SendEmailAsync没有Email发送的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用下面的代码来尝试异步发送电子邮件,但没有发送电子邮件,我不知道正在做什么错误。我还添加了代码的第二段在web.config的收发邮件协议。



SendEmailAsync代码



 等待UserManager.SendEmailAsync(username.IdMTSS-b:忘记密码,这是您的新密码,请回到MTSS-b。 。网络工具,并登入系统将提示您创建自己的密码< BR />< BR />中+ tmpPass +< BR />< BR /> MTSS-B管理员 ); 



的Web.config代码



 < system.net> 
< mailSettings>
<&SMTP GT;
<网络主机=smtp1.airws.org的userName =密码=/>
< / SMTP>
< / mailSettings>
< /system.net>



**** ****更新



我测试如果电子邮件可以用通常的方法来发送和邮件能够用下面的代码来发送。

  MAILMESSAGE M = MAILMESSAGE新(新MailAddress(ConfigurationManager.AppSettings [SupportEmailAddr]),新的MailAddress(model.Email)); 
m.Subject =MTSS-B:忘记密码; 。
m.Body =的String.Format(这是您的新密码,请回到MTSS-B的网络工具,并登录系统将提示您创建自己的密码< BR />< ; BR />密码:+ tmpPass +< BR />< BR /> MTSS-B管理员);
m.IsBodyHtml = TRUE;
SmtpClient SMTP =新SmtpClient(smtp2.airws.org);
smtp.Send(米);


解决方案

在您的应用程序,你可能有一个名为 IdentityConfig.cs App_Start 文件夹中。这个文件可能有这样的事情朝上方:

 公共类EmailService:IIdentityMessageService 
{
公任务SendAsync(IdentityMessage消息)
{
//在此插入您的电子邮件服务发送电子邮件。
返回Task.FromResult(0);
}
}



将其更改为:

 公共类EmailService:IIdentityMessageService 
{
公共任务SendAsync(IdentityMessage消息)
{
SmtpClient客户端=新SmtpClient();
返回client.SendMailAsync(ConfigurationManager.AppSettings [SupportEmailAddr],
message.Destination,
message.Subject,
message.Body);
}
}



自定义发送代码到你的喜好。


I am using the following code to try to send an email asynchronously, but no email is sent and I am not sure what is being done incorrectly. I have also added the 2nd segment of code in the web.config for the emailing protocol.

SendEmailAsync code

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 code

<system.net>
<mailSettings>
  <smtp>
    <network host="smtp1.airws.org" userName="" password="" />
  </smtp>
</mailSettings>
</system.net>

****UPDATE****

I tested if an email could be sent with the usual method and an email was able to be sent using the following code.

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);
解决方案

In your app you probably have a file called IdentityConfig.cs in the App_Start folder. That file probably has something like this towards the top:

public class EmailService : IIdentityMessageService
{
    public Task SendAsync(IdentityMessage message)
    {
        // Plug in your email service here to send an email.
        return Task.FromResult(0);
    }
}

change it to:

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

Customizing the send code to your liking.

这篇关于的UserManager SendEmailAsync没有Email发送的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 04:16