简体   繁体   中英

Cannot send mail from an Azure VM using Gmail

I am trying to send Email from an asp.net webform using Gmail. the code works from my machine but when I upload the code to my windows server 2012 in Azure I get Unable to connect to Remote Server - exception

here is my code:

MailMessage mail = new MailMessage();
mail.Subject = "Subject";
mail.Body = "Main body goes here";

mail.From = new MailAddress("myAcount@gmail.com");

mail.IsBodyHtml = true;
mail.BodyEncoding = System.Text.Encoding.Unicode;
mail.SubjectEncoding = System.Text.Encoding.Unicode;

mail.To.Add("aaaa@gmail.com");

NetworkCredential cred = new NetworkCredential("myAccount@gmail.com", "myPwd"); 
SmtpClient smtp = new SmtpClient("smtp.gmail.com");
smtp.EnableSsl = true;

smtp.Credentials = cred;
smtp.Port = 587;
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;

smtp.Send(mail);

Any ideas?

确保本地VM的防火墙规则允许通过端口587进行传出连接。 这是一篇关于如何创建出站防火墙规则的好文章

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM