Swiftmailer:无法与主机 smtp.gmail.com 建立连接 [连接超时 #110]

问题描述:

我发帖是因为我已经完成了此处其他问题中发布的解决方案,但它们没有帮助.

I'm posting because I've already gone through the solutions posted in other questions on here but they haven't helped.

我想要做的是通过 Google Apps for Business Gmail 使用 Swiftmailer 发送电子邮件,但我不断收到此错误:

What I am trying to do is send email using Swiftmailer through Google Apps for Business Gmail but I keep getting this error:

无法与主机 smtp.gmail.com 建立连接 [连接超时 #110]

Connection could not be established with host smtp.gmail.com [Connection timed out #110]

我知道代码很好,因为它可以在我的本地机器上运行,但不能在生产服务器上运行.

I know the code is fine because it works on my local machine but not on the production server.

到目前为止我尝试过的:

What I have tried so far:

  • 启用 OpenSSL.
  • 从 Google 验证码解锁帐户.
  • 使用了应用程序专用密码.
  • 列入白名单的 Gmail SMTP IP 地址

配置:

# Swiftmailer Configuration
swiftmailer:
    transport:  smtp
    encryption: ssl
    auth_mode:  login
    host:       smtp.gmail.com
    username:   contact@mydomain.com
    password:   applicationspecificpassword
    port:       465

我还能尝试什么?这可能是 DNS 问题,因为我使用的是 Gmails SMTP MX 记录而不是服务器.

What else can I try? Could this be a DNS issue since I am using Gmails SMTP MX records instead of the servers.

以下步骤对我有用:

  1. 检查 httpd_can_sendmail 是否打开,运行这个 getsebool httpd_can_sendmail

  1. Check if httpd_can_sendmail is on , run this getsebool httpd_can_sendmail

  • 当你得到: httpd_can_sendmail --> off 时,运行 setsebool -P httpd_can_sendmail 1
  • 当您收到:httpd_can_sendmail --> 开启时,就可以进行第 2 步了.
  • When you get: httpd_can_sendmail --> off , run setsebool -P httpd_can_sendmail 1
  • When you get: httpd_can_sendmail --> on that's fine move on step 2.

还要检查 httpd_can_network_connect 是否打开,运行 getsebool httpd_can_network_connect

Check also if httpd_can_network_connect is on, run getsebool httpd_can_network_connect

  • 当您获得 httpd_can_network_connect --> off 时,运行 setsebool -P httpd_can_network_connect 1
  • 当您获得:httpd_can_network_connect --> 开启时,就可以继续第 3 步了.
  • When you get httpd_can_network_connect --> off run setsebool -P httpd_can_network_connect 1
  • When you get: httpd_can_network_connect --> on that's fine move on step 3.

我正在使用 Centos

I'm using Centos