所有端口上通过 C# .Net 的 GMail SMTP 错误

GMail SMTP via C# .Net errors on all ports(所有端口上通过 C# .Net 的 GMail SMTP 错误)

本文介绍了所有端口上通过 C# .Net 的 GMail SMTP 错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试解决这个问题,但到目前为止一直失败得很惨.我最近的尝试是从这里的堆栈代码中提取的:通过 Gmail 发送电子邮件使用 C# 的 SMTP 服务器,但我已经尝试了所有可以在堆栈和其他地方找到的语法.我目前的代码是:

I've been trying for a whlie on this, and have so far been failing miserably. My most recent attempt was lifted from this stack code here: Sending email through Gmail SMTP server with C#, but I've tried all the syntax I could find here on stack and elsewhere. My code currently is:

var client = new SmtpClient("smtp.gmail.com", 587)
{
    Credentials = new NetworkCredential("me@gmail.com", "mypass"),
    EnableSsl = true
};

client.Send("me@gmail.com","me@gmail.com","Test", "test message");

运行该代码会给我一个即时异常发送邮件失败",其中包含无法连接到远程服务器"的内部解释.

Running that code gives me an immediate exception "Failure sending mail" that has an innerexeption "unable to connect to the remote server".

如果我将端口更改为 465(如 gmail 文档建议的那样),我每次都会超时.

If I change the port to 465 (as gmail docs suggest), I get a timeout every time.

我读到 465 不是一个好用的端口,所以我想知道 587 是怎么回事,让我无法连接.我的用户和通行证是正确的.我读到我必须在我的 gmail 帐户上设置 POP 服务,所以我这样做了.没用.

I've read that 465 isn't a good port to use, so I'm wondering what the deal is w/ 587 giving me failure to connect. My user and pass are right. I've read that I have to have POP service setup on my gmail account, so I did that. No avail.

我最初试图让这个为我的品牌 GMail 帐户工作,但在遇到相同的问题之后,我认为使用我的常规 gmail 帐户会更容易......所以远非如此.

I was originally trying to get this working for my branded GMail account, but after running into the same problems w/ that I thought going w/ my regular gmail account would be easier... so far that's not the case.

推荐答案

我试过你的代码,它在 587 端口上可以正常工作,但在 465 端口上不行.

I tried your code, and it works prefectly with port 587, but not with 465.

你检查过防火墙吗?从命令行尝试Telnet smtp.gmail.com 587"如果您返回220 mx.google.com ESMTP....",则端口已打开.如果不是,它会阻止你调用.

Have you checked the fire wall? Try from the command line "Telnet smtp.gmail.com 587" If you get "220 mx.google.com ESMTP...." back, then the port is open. If not, it is something that blocks you call.

丹尼尔

这篇关于所有端口上通过 C# .Net 的 GMail SMTP 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:所有端口上通过 C# .Net 的 GMail SMTP 错误

基础教程推荐