【问题标题】:Cannot send mail from an Azure VM using Gmail无法使用 Gmail 从 Azure VM 发送邮件
【发布时间】:2013-06-24 19:49:53
【问题描述】:

我正在尝试使用 Gmail 从 asp.net 网络表单发送电子邮件。 该代码可以在我的机器上运行,但是当我将代码上传到 Azure 中的 Windows Server 2012 时,我得到了 无法连接到远程服务器 - 异常

这是我的代码:

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);

有什么想法吗?

【问题讨论】:

  • 你的虚拟机上的 587 端口是否打开?

标签: email azure smtp outgoing-mail


【解决方案1】:

确保本地 VM 的防火墙规则允许通过端口 587 进行传出连接。Here is a good article 了解如何创建出站防火墙规则。

【讨论】:

    猜你喜欢
    • 2021-01-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-19
    • 2014-09-13
    • 2011-11-30
    • 1970-01-01
    • 2017-04-30
    相关资源
    最近更新 更多