ASP.NET 无法通过 Gmail SMTP 发送电子邮件,但 Outlook 2007 成功

发布于 2024-10-07 01:58:04 字数 378 浏览 0 评论 0原文

大家好 几周前,我的 ASP.NET 网站停止发送用户评论,我是通过 Gmail SMTP 服务器 (smtp.gmail.com) 将这些评论通过电子邮件发送到我的电子邮件帐户来实现的。我在开发计算机上打开该项目,几分钟后再次无法发送电子邮件,并出现以下异常消息:

发送邮件失败

无法从传输连接读取数据:net_io_connectionclosures。

我使用 Gmail 的 SMTP 端口 465,并且 MailClient.EnableSSL = True。 奇怪的是我的 Office Outlook 2007 使用相同的设置,并且使用相同的 Gmail 帐户发送邮件没有任何问题。

有什么想法吗?

Hi all
a couple weeks ago, my ASP.NET website stopped sending user comments which I implemented by emailing those comments to my email account through Gmail SMTP server (smtp.gmail.com). I opened the project on my development machine and again it fails to send the email after a couple minutes with the following exception message:

Failure sending mail

Unable to read data from the transport connection: net_io_connectionclosed.

I'm using Gmail's SMTP with port 465, and MailClient.EnableSSL = True.
The weird thing is my Office Outlook 2007 is using the same settings and it doesn't have any problems sending mail using the same Gmail account.

Any thoughts?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

嗳卜坏 2024-10-14 01:58:04

这段代码对我有用。请注意,端口号与您尝试的 465 不同。我几乎可以肯定我也先尝试过 465,但没有成功。

var msg = new MailMessage(new MailAddress(recipient, "SCS Web Site"), new MailAddress(toAddress))
                {
                    Body = BuildMailBody(),
                    Subject = "SCS Web Site Message"
                };
var smtp = new SmtpClient
                {
                    Host = "smtp.gmail.com",
                    Port = 587,
                    EnableSsl = true,
                    UseDefaultCredentials = false,
                    Credentials = new NetworkCredential(myGmailUser, myGmailPassword)
                };
smtp.Send(msg);

This code works for me. Note the port number is different to the 465 you are trying. I'm almost certain I also tried 465 first with no luck.

var msg = new MailMessage(new MailAddress(recipient, "SCS Web Site"), new MailAddress(toAddress))
                {
                    Body = BuildMailBody(),
                    Subject = "SCS Web Site Message"
                };
var smtp = new SmtpClient
                {
                    Host = "smtp.gmail.com",
                    Port = 587,
                    EnableSsl = true,
                    UseDefaultCredentials = false,
                    Credentials = new NetworkCredential(myGmailUser, myGmailPassword)
                };
smtp.Send(msg);
糖果控 2024-10-14 01:58:04

您不会碰巧有防火墙禁止此处的出站连接,比如说,专门允许 Outlook 穿透。 。 。

You wouldn't happen to have a firewall disallowing outbound connections here then, say, specifically allowed outlook to punch through . . .

海拔太高太耀眼 2024-10-14 01:58:04

我发现 formmail 通过 gmail(在 Windows 服务器上)时出现的一个奇怪现象是端口号有问题。我的代码与您的类似,但仅当我将端口更改为 25 而不是 587 或 465 时它才有效。这可能就是您所需要的。

One oddity I found with formmail going through gmail (on Windows server) was that the port number was the problem. My code was similar to yours, but it only worked when I changed the port to 25 rather than the 587 or 465. That might be what you need here.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文