这是什么原因使用C#不到位从Gmail的SMTP发送的消息 - 不会出现异常不到位、这是什么原因、异常、消息

由网友(滚,不配和哥玩)分享简介:我想通过我的谷歌企业应用套件电子邮件帐户发送邮件。这是建立在自己的域名,并且通过Web界面,并通过Outlook中的所有工作的罚款。I am trying to send mail through my Google Apps email account. This is setup on my own domain...

我想通过我的谷歌企业应用套件电子邮件帐户发送邮件。这是建立在自己的域名,并且通过Web界面,并通过Outlook中的所有工作的罚款。

I am trying to send mail through my Google Apps email account. This is setup on my own domain and is all working fine through the web interface and through outlook.

不过,我试图使用C#从网页发送一封电子邮件,我没有得到任何的异常,一切看似顺利,但电子邮件似乎从未到达:

However, i'm trying to send an email from a webpage using C#, I get no exceptions and everything appears to go smoothly, but the emails never seem to arrive:

MailMessage msg = new MailMessage("no-reply@xxxx.co.uk", "dan@xxxx.co.uk");
    SmtpClient smtp = new SmtpClient("smtp.gmail.com", 587);
    smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
    smtp.Credentials = new NetworkCredential("no-reply@xxxx.co.uk", "xxxxxxxxx");
    smtp.EnableSsl = true;
    msg.IsBodyHtml = true;
    msg.Body = body;

    smtp.Send(msg);

身体是我已经在前面的code生成的字符串。据我所知,如果有与实际连接到SMTP服务器上的Gmail,那么我会得到一个异常抛出一个问题。

The body is a string which i've generated earlier in the code. As far as i'm aware, if there was a problem with actually connecting to the SMTP server at Gmail then I would get an exception thrown.

任何想法可能导致此不工作?唯一不同的,我可以看到相对于其他民族的例子是,我已经设置身体为HTML,我从谷歌企业应用套件发送帐户,而不是一个@ gmail.com帐户。

Any ideas what could cause this not to work? Only thing different I can see compared to other peoples examples is that I have set body as HTML and i'm sending from a Google Apps account rather than an @gmail.com account.

在谷歌应用程序本身所有的完全配置和工作,我已经设置这无数次,所以我知道这不太可能是一个问题。

The google apps itself is all configured fully and working, i've set this up numerous times so I know it's not likely to be a problem there.

我也试过发送端口25上,因为这是配置Outlook以从Gmail帐户发送的时候你用什么。

I also tried sending on port 25, as that's what you use when configuring Outlook to send from a Gmail account.

同样的结果为,没有抛出异常,但邮件永远不会到来。这两个邮件发送者和接收者都在使用谷歌应用服务的Gmail我的域名。

Same result for both, no exception thrown, but email never arrives. Both emails the sender and receiver are on my domain using Google Apps for Gmail.

编辑:

另外,我要指出,我在使用这两个帐户已经签署,并在其设置有两个IMAP和POP启用等。

Also I should mention that I have signed in using both accounts, and both have IMAP and POP enabled in their settings etc.

新发现

这是一个奇怪的一个

如果我手动发送邮件:

no-reply@mydomain.com to dan@mydomain.com - Then it works

But if I send it through code this way...it doesn't work...

如果我把下面通过code它的工作:

If I send the following through code it does work:

no-reply@mydomain.com to me@gmail.com or me@ntlworld.com - This works through code!

然后我会被领导认为,这意味着一个问题dan@mydomain.com接收消息...但它接收来自任何谷歌,Hotmail或ntlworld电子邮件地址,我试过手动发送的任何消息。

I would then be led to think that this means a problem with dan@mydomain.com receiving messages...But it receives any messages sent manually from any google, hotmail, or ntlworld email address i've tried.

所以,无论是谷歌Apps帐户无法接收电子邮件至code(不太可能)发送或其他什么东西在作怪这里

So either Google Apps accounts can't receive email sent through code (unlikely) or something else is at play here

推荐答案

在安装谷歌企业应用套件,即使MX记录都在正常工作手动将邮件发送到/从其他帐户,有可能仍是问题。

When you setup Google Apps, even if the MX records are all working correctly for sending mail manually to/from other accounts, there can still be problems.

答案是等待12-24小时设置您的MX记录,即使一切工作正常后。

The answer is to wait 12-24 hours after setting up your MX Records, even if everything else is working fine.

如果您收到没有异常,那么对我来说这是目前唯一的答案。

If you receive no exception, then to me this is the only answer at the moment.

所有工作正常了。即使所有的MX记录都在我的DNS正确和电子邮件似乎是工作,仍然有改变的背景回事

All is working correctly now. Even though all MX records were correct on my DNS and email appeared to be working, there were still changes going on in the background

阅读全文

相关推荐

最新文章