什么可能导致使用 C# 从 Gmail SMTP 发送的邮件无法到达 - 不会引发异常

发布于 2024-10-17 18:27:21 字数 2563 浏览 1 评论 0原文

我正在尝试通过我的 Google Apps 电子邮件帐户发送邮件。这是在我自己的域上设置的,并且通过 Web 界面和 Outlook 一切正常。

但是,我尝试使用 C# 从网页发送电子邮件,没有任何例外,一切似乎都很顺利,但电子邮件似乎从未到达:

MailMessage msg = new MailMessage("[email protected]", "[email protected]");
    SmtpClient smtp = new SmtpClient("smtp.gmail.com", 587);
    smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
    smtp.Credentials = new NetworkCredential("[email protected]", "xxxxxxxxx");
    smtp.EnableSsl = true;
    msg.IsBodyHtml = true;
    msg.Body = body;

    smtp.Send(msg);

正文是我之前在代码中生成的字符串。据我所知,如果实际连接 Gmail 的 SMTP 服务器出现问题,我会抛出异常。

有什么想法可能会导致此功能不起作用吗?与其他人的示例相比,我能看到的唯一不同之处是我将正文设置为 HTML,并且从 Google Apps 帐户而不是 @gmail.com 帐户发送。

谷歌应用程序本身已完全配置并正常工作,我已经设置了很多次,所以我知道这不太可能成为问题。

我还尝试在端口 25 上发送,因为这是将 Outlook 配置为从 Gmail 帐户发送时使用的端口。

两者的结果相同,没有抛出异常,但电子邮件从未到达。发件人和收件人的电子邮件均位于我的域中,并且使用 Google Apps for Gmail。

编辑:

另外我应该提到,我已经使用这两个帐户登录,并且都在其设置中启用了 IMAP 和 POP 等。

新发现

这是一个奇怪的问题

如果我手动发送邮件:

[email protected] to [email protected] - Then it works

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

如果我通过它确实有效的代码发送以下内容:

[email protected] to [email protected] or [email protected] - This works through code!

然后我会认为这意味着 [email protected] 接收消息...但它会接收从我尝试过的任何 google、hotmail 或 ntlworld 电子邮件地址手动发送的任何消息。

因此,要么 Google Apps 帐户无法接收通过代码发送的电子邮件(不太可能),要么这里有其他原因在起作用

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.

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("[email protected]", "[email protected]");
    SmtpClient smtp = new SmtpClient("smtp.gmail.com", 587);
    smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
    smtp.Credentials = new NetworkCredential("[email protected]", "xxxxxxxxx");
    smtp.EnableSsl = true;
    msg.IsBodyHtml = true;
    msg.Body = body;

    smtp.Send(msg);

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.

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.

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

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.

EDIT:

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

New findings

This is a strange one

If I send mail manually from:

[email protected] to [email protected] - Then it works

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

If I send the following through code it does work:

[email protected] to [email protected] or [email protected] - This works through code!

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

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

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

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

发布评论

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

评论(2

纸伞微斜 2024-10-24 18:27:21

如果存在问题,服务器可能会默默地丢弃您的消息。
- 尽管任何规范另有说明。

尽管消息被“传递”,但它可能会在以太中丢失。

SMTP 服务器可能正在应用严格的过滤,并且可能还要求您的发件人和目标电子邮件地址“正确”匹配,

我建议尝试使用不同的 SMTP 主机进行检查。 :)

The server may silently discard your message if there is a problem with it.
- Despite any spec saying otherwise.

The message might be lost in the ether despite being "delivered".

The SMTP server may be applying severe filtering and might additionally require that your sender and destination email addresses match up 'correctly'

I suggest trying with a different SMTP host just to check. :)

猫弦 2024-10-24 18:27:21

当您设置 Google Apps 时,即使 MX 记录都可以正常工作以手动向/从其他帐户发送邮件,仍然可能会出现问题。

答案是在设置 MX 记录后等待 12-24 小时,即使其他一切正常。

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

现在一切正常。尽管我的 DNS 上的所有 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.

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.

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

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