I'm trying to send a mail with my gmailaccount from a server with the following code.
var fromAddress = new MailAddress("xxxxx@gmail.com", "xxxxxx");
var toAddress = new MailAddress(toMailAddress);
const string fromPassword = "xxxxx";
var smtp = new SmtpClient
{
Host = "smtp.gmail.com",
Port = 587,
EnableSsl = true,
DeliveryMethod = SmtpDeliveryMethod.Network,
UseDefaultCredentials = false,
Credentials = new NetworkCredential(fromAddress.Address, fromPassword)
};
using (var message = new MailMessage(fromAddress, toAddress)
{
IsBodyHtml = true,
Subject = mailSubject,
Body = htmlBody
})
{
smtp.Send(message);
}
This gives the next result when I deploy it on my windows server although I have an Inobound Rule for port 587 on the firewall. It works perfect when I test it local