来自服务器的用户未与 smtp.gmail.com 通信

User from server not communicating with smtp.gmail.com

我有一个带有 Bluehost 的专用服务器,我在其中运行了几个脚本和项目(特别是 Python)。其中之一包括通过 smtp.gmail.com、端口 465 的基本电子邮件发件人,但它随机停止工作。挖啊挖,我意识到我在那个服务器上的用户没有成功地与 smtp.gmail.com 通信。但事实证明它既没有与 smtp.live.com 也没有与 imap.gmail.com 通信,所以我猜那里有问题。

当我执行命令时:openssl s_client -crlf -connect smtp.gmail.com:465 thorugh sudo(或直接从 root 用户),在服务器中这些是输出:

CONNECTED(00000003)
depth=2 C = US, O = Google Trust Services LLC, CN = GTS Root R1
verify return:1
depth=1 C = US, O = Google Trust Services LLC, CN = GTS CA 1C3
verify return:1
depth=0 CN = imap.gmail.com
verify return:1
---
Certificate chain
 0 s:CN = imap.gmail.com
   i:C = US, O = Google Trust Services LLC, CN = GTS CA 1C3
 1 s:C = US, O = Google Trust Services LLC, CN = GTS CA 1C3
   i:C = US, O = Google Trust Services LLC, CN = GTS Root R1
 2 s:C = US, O = Google Trust Services LLC, CN = GTS Root R1
   i:C = BE, O = GlobalSign nv-sa, OU = Root CA, CN = GlobalSign Root CA
---
Server certificate
-----BEGIN CERTIFICATE-----
blablablabla
.
.
.
blablablabla
-----END CERTIFICATE-----
subject=CN = imap.gmail.com
.
.
.
etc

来自我的用户:

CONNECTED(00000003)
depth=3 C = GB, ST = Greater Manchester, L = Salford, O = Comodo CA Limited, CN = AAA Certifi        cate Services
verify return:1
depth=2 C = GB, ST = Greater Manchester, L = Salford, O = COMODO CA Limited, CN = COMODO RSA         Certification Authority
verify return:1
depth=1 C = US, ST = TX, L = Houston, O = "cPanel, Inc.", CN = "cPanel, Inc. Certification Au        thority"
verify return:1
depth=0 CN = [My server name!!!!! WHY?????]
verify return:1
---
Certificate chain
 0 s:/CN=[my server name]
   i:/C=US/ST=TX/L=Houston/O=cPanel, Inc./CN=cPanel, Inc. Certification Authority
 1 s:/C=US/ST=TX/L=Houston/O=cPanel, Inc./CN=cPanel, Inc. Certification Authority
   i:/C=GB/ST=Greater Manchester/L=Salford/O=COMODO CA Limited/CN=COMODO RSA Certification Au        thority
 2 s:/C=GB/ST=Greater Manchester/L=Salford/O=COMODO CA Limited/CN=COMODO RSA Certification Au        thority
   i:/C=GB/ST=Greater Manchester/L=Salford/O=Comodo CA Limited/CN=AAA Certificate Services
---
Server certificate
-----BEGIN CERTIFICATE-----
blablablabla
    .
    .
    .
blablablabla
-----END CERTIFICATE-----
subject=CN = [My server again] 
    .
    .
    .
    etc

imap.gmail.com、smtp.live.com 也发生了同样的事情,我想等等。我的服务器似乎是在与自身通信,而不是与外部服务器通信。 通过端口 443 对网站的其他 openSSL 查询工作完美,而且重要的是,当我执行 Telnet smtp.gmail.com 25 时,它也连接到我自己的服务器,而不是 sudo/root 用户的情况,它工作完美.

我可以用 SSL 或类似的东西破坏一些东西吗?

谢谢!

对于共享主机,对外部系统的访问仅限于端口 80 和 443。引用自 Bluehost Web Hosting Help - Script Cannot Make Outbound Connection:

Our shared IP addresses only allow outbound connection on ports 80(http), 443(https). ... To discourage spam from our servers, we do not allow outbound connections to ports 25 and 465 with or without a dedicated IP.

最好的解决方案是联系 Bluehost,在扩展到他们的高级团队后,他们得到了解决方案:

Hello,

Thank you for your response, explaining the issue you are experiencing further.

There is a setting in the WHM that only allows outbound SMTP connections from root, exim and mailman.  I set that to off so you will now be able to connect via SMTP as the cPanel user and not just as root.