gpt4 book ai didi

email - 无法使用 Gmail 从 Azure VM 发送邮件

转载 作者:行者123 更新时间:2023-12-02 02:00:49 25 4
gpt4 key购买 nike

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

这是我的代码:

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

mail.From = new MailAddress("<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="80edf9c1e3eff5eef4c0e7ede1e9ecaee3efed" rel="noreferrer noopener nofollow">[email protected]</a>");

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

mail.To.Add("<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="4829292929082f25292124662b2725" rel="noreferrer noopener nofollow">[email protected]</a>");

NetworkCredential cred = new NetworkCredential("<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="caa7b38ba9a9a5bfa4be8aada7aba3a6e4a9a5a7" rel="noreferrer noopener nofollow">[email protected]</a>", "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 进行传出连接。Here is a good article关于如何创建出站防火墙规则。

关于email - 无法使用 Gmail 从 Azure VM 发送邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17283862/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com