通过 Google Apps 帐户发送电子邮件可以在本地运行,但不能在我的网络服务器上运行

发布于 2024-07-25 13:33:44 字数 1617 浏览 5 评论 0原文

有关的:

通过 Google Apps 帐户通过 C# 发送电子邮件< /p>

我的问题是同样,我实现了 Koistya 的解决方案,如下所示。 令人心碎的是,它在我的开发笔记本电脑上运行得很好,但当移植到网络服务器时,它会超时且没有任何解释。

我的 SMTP 配置位于我的 web.config 文件中。 我根据 Koistya 的答案制作了 mod:

<mailSettings>
    **Changed**
      <smtp from="[email protected]">
        <network host="smtp.gmail.com" password="[password]" port="587" 
          userName="[email protected]"/>
      </smtp>
    **Original**
      <!--<smtp from="[email protected]">
        <network host="mail.domain.com" password="[password]" port="25"
          userName="[email protected]"/>
      </smtp>-->
</mailSettings>

我的 .Net C# 代码(删除之前和之后):

  SmtpClient mSmtpClient = new SmtpClient();
  mSmtpClient.EnableSsl = true;
  mSmtpClient.Send(message);

正如我所说,这在我的开发环境中效果很好,但在网络上则不然。 有人可以帮忙吗? 谢谢。

Related:

Send Email via C# through Google Apps account

My question is the same so I implemented Koistya's solution as follows. The heartbreak is that it works beautifully on my dev laptop but when ported to web server it times out with no explanation.

My SMTP config is in my web.config file. I made mods based on Koistya's answer:

<mailSettings>
    **Changed**
      <smtp from="[email protected]">
        <network host="smtp.gmail.com" password="[password]" port="587" 
          userName="[email protected]"/>
      </smtp>
    **Original**
      <!--<smtp from="[email protected]">
        <network host="mail.domain.com" password="[password]" port="25"
          userName="[email protected]"/>
      </smtp>-->
</mailSettings>

My .Net C# code (before & after removed):

  SmtpClient mSmtpClient = new SmtpClient();
  mSmtpClient.EnableSsl = true;
  mSmtpClient.Send(message);

As I said this works great on my dev environment but not on web. Can anyone help? Thanks.

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

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

发布评论

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

评论(6

风铃鹿 2024-08-01 13:33:44

您的设置是正确的。 我们在网络应用程序中始终使用 gmail 发送邮件。 您的服务器可能阻止端口 587 上的传出流量。我会联系您的主机,看看他们是否可以提供帮助,否则您将需要新邮件或新主机。

Your settings are correct. We use gmail for sending mail all the time in our web apps. Your server is probably blocking outgoing traffic on port 587. I would contact your host and see if they can help otherwise you will need new mail or a new host.

我是男神闪亮亮 2024-08-01 13:33:44

感谢这个网站以及 Google 应用程序论坛上每个人的帮助(虽然我更喜欢这个),我终于把拼图的所有部分拼凑起来。 无论出于何种原因,端口 465 和端口 587 都无法工作。 这对我有用:

Web.config:

  <smtp from="[email protected]">
    <network host="smtp.gmail.com" password="[password]" port="25" 
      userName="[email protected]"/>
  </smtp>

来自 aspx.cs 文件:

SmtpClient mSmtpClient = new SmtpClient();
mSmtpClient.EnableSsl = true;

再次感谢!

Thanks to everyone's help on this site as well as the Google apps forum (although I like this one better) I finally put together all the pieces of the puzzle. For whatever reason port 465 and port 587 would not work. This is what worked for me:

Web.config:

  <smtp from="[email protected]">
    <network host="smtp.gmail.com" password="[password]" port="25" 
      userName="[email protected]"/>
  </smtp>

from the aspx.cs file:

SmtpClient mSmtpClient = new SmtpClient();
mSmtpClient.EnableSsl = true;

Thanks again!

深海蓝天 2024-08-01 13:33:44

我的表格也有同样的问题。 我的网站在 Plesk 控制面板上运行。 我所做的就是登录我的面板并禁用我的网络服务器上的电子邮件托管。 之后我的表格开始发送到 Google Apps 帐户。 尝试一下我所做的,我相信你会有所不同。

I had the same problem for my form. My website is running on a Plesk control panel. All I did was to login to my panel and disable email hosting on my web server. After that my form started sending to a Google apps account. Try out what I did, I am sure you will get a difference.

听闻余生 2024-08-01 13:33:44

如果您的托管公司没有响应,并且如果您有另一台服务器可以向其发送测试请求,请尝试请求连接到其他端口,看看会发生什么。

Failing a response from your hosting company and if you have another server you could send test requests to, try requesting connections to other ports and see what happens.

两人的回忆 2024-08-01 13:33:44

可能是 smtp 客户端无法访问 smtp 服务器(可能被 Web 主机禁用)。

询问网络主机是否有您应该用来发送电子邮件的特定 smtp 服务器。

Could be that the smtp client is not able to access the smtp server (might be disabled by the web host).

Ask the web host if they have a specific smtp server you should be using to send emails with.

月野兔 2024-08-01 13:33:44

如果您的虚拟主机不允许您从其服务器发送外发 SMTP 邮件,则会导致此问题。 例如,GoDaddy 只允许您通过 smtpout.secureserver.net 从您的服务器发送外发邮件,因此任何通过其他主机(在本例中为 smtp.gmail.com)发送邮件的尝试都会失败。 如果您的 ISP 不阻止传出 SMTP(例如 Qwest 就不阻止),那么这就是它在本地起作用的原因。

请与您的虚拟主机查看常见问题解答,看看他们对此有什么看法。 大多数托管公司确实允许传出 SMTP,但将其限制为每天一定数量的中继,以防止意外利用垃圾邮件转发。

您的域中的 MX 记录仅影响传入邮件,这是正确的。 当有人尝试将邮件发送到 [email protected] 时,他们会将其交给SMTP 服务器(很可能是他们的 ISP 提供的),然后 SMTP 服务器查找您的 MX 记录以了解谁处理您的电子邮件。 它将解析为 smtp.gmail.com,这样谁就会收到您的邮件,您也可以从他们那里收到邮件。 当您发送外发邮件时,它可以通过任何人,因为您只关心目标域(邮件最终将到达的地方)的 MX 记录。

那有意义吗? 如果您需要一些说明,我可以找到一些教程和其他解释来帮助您理解它。

If your webhost doesn't allow you to send outgoing SMTP mail from their servers, that would cause this problem. For example, GoDaddy only allows you to send outgoing mail through smtpout.secureserver.net from your server, so any attempt to send mail through another host (in this case, smtp.gmail.com) would fail. If your ISP does not block outgoing SMTP (like Qwest does not, for example), then that's why this would work locally.

Check the FAQ with your webhost to see what they have to say about it. Most hosting companies do allow outgoing SMTP, but limit it to a certain number of relays/day, to prevent accidental exploitation for spam forwarding.

You're correct that the MX record on your domain only affects incoming mail. When somebody tries to send mail to [email protected], they hand it to an SMTP server (most likely, the one their ISP gives them), and then SMTP server looks up your MX record to see who handles your email. It will resolve to smtp.gmail.com, so that's who will get your mail, and you get it from them. When you send outgoing mail, it can go through anybody, since you only care about the MX record for the destination domain (where the mail will eventually end up).

Does that make sense? If you'd like some clarification, I can find some tutorials and other explanations to help make sense of it.

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