I am trying to send email to the user in asp.net MVC using identity 2. It works fine on localhost but when I upload it on server, it does not send email.
This is what I have in controller:
await UserManager.SendEmailAsync(user.Id, "EmailSubject", "emailText");
And this is what I have in 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);
}
Well I changed the Smtp port to 25 like this:
SmtpServer.Port = 25;
And it worked!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.