【发布时间】: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