UserManager.SendEmailAsync在localhost上有效,但在服务器上不起作用

问题描述 投票:0回答:1

我正在尝试使用身份2向asp.net MVC中的用户发送电子邮件。它在localhost上运行良好,但是当我在服务器上将其上传时,它不会发送电子邮件。

这是我在控制器中拥有的:

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个回答
0
投票

好吧,我将Smtp端口更改为25:

SmtpServer.Port = 25;

它成功了!

© www.soinside.com 2019 - 2024. All rights reserved.