【问题标题】:UserManager.SendEmailAsync works on localhost but does not work on serverUserManager.SendEmailAsync 适用于 localhost 但不适用于服务器
【发布时间】:2020-09-03 03:35:46
【问题描述】:

我正在尝试使用身份 2 在 asp.net MVC 中向用户发送电子邮件。 它在本地主机上工作正常,但是当我将它上传到服务器上时,它不会发送电子邮件。

这是我在控制器中的内容:

await UserManager.SendEmailAsync(user.Id, "EmailSubject", "emailText");

这就是我在 IdentityConfig.cs 中的内容:

public Task SendAsync(IdentityMessage message)
        {
            MailMessage mail = new MailMessage();
            SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");
            mail.From = new MailAddress("myGmailAddress", "MyWebsiteAddress");
            mail.To.Add(message.Destination);
            mail.Subject = message.Subject;
            mail.Body = message.Body;
            mail.IsBodyHtml = true;
            SmtpServer.Port = 587;
            SmtpServer.Credentials = new System.Net.NetworkCredential("myGmailAddress", "myGmailPassword");
            SmtpServer.EnableSsl = true;            
            return SmtpServer.SendMailAsync(mail);
        }

【问题讨论】:

    标签: asp.net-mvc asp.net-identity-2


    【解决方案1】:

    我将 Smtp 端口更改为 25,如下所示:

    SmtpServer.Port = 25;
    

    它成功了!

    【讨论】:

      猜你喜欢
      • 2012-01-01
      • 1970-01-01
      • 2016-04-02
      • 1970-01-01
      • 2014-04-19
      • 2019-09-09
      • 2015-07-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多