Swiftmailer: Connection could not be established with host smtp.gmail.com [Connection timed out #110]
Asked Answered
P

8

22

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

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

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:

  • Enabled OpenSSL.
  • Unblocked account from Google captcha.
  • Used an Application Specific Password.
  • Whitelisted Gmail SMTP IP addresses

Configuration:

# Swiftmailer Configuration
swiftmailer:
    transport:  smtp
    encryption: ssl
    auth_mode:  login
    host:       smtp.gmail.com
    username:   [email protected]
    password:   applicationspecificpassword
    port:       465

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

Prissie answered 27/8, 2014 at 0:47 Comment(5)
It seems that there is a firewall that blocks the port 465 ...Hurds
Log into the production service and type telnet smtp.gmail.com 465. What happen ? Is the connection established ?Thulium
Hi @Hurds @hpatoio, root@host [~]# telnet smtp.gmail.com 465 Trying xx.xxx.xx.xxx... Connected to smtp.gmail.comPrissie
I tried changing my Swiftmailer configuration to another email account hosted internally/add-on domain and that worked. I think I'll deactivate Google Apps and return to the hosts email.Prissie
Your swiftmailer configuration is correct, so it is not a problem of Swiftmailer itself. I agree, there is something external, blocking you to connect to the specific host.Schlenger
A
15

The following steps worked for me :

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

    • 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.
  2. Check also if httpd_can_network_connect is on, run getsebool httpd_can_network_connect

    • 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.
  3. Use the following settings for smtp : 'host' => '64.233.166.108' 'port' => '465'

I'm using Centos

Apterous answered 3/9, 2015 at 18:50 Comment(2)
this answer is awesome! save my life, thanks. Must take a look if you're use CentOSSweet
Please set this as the correct answer. This also solved my issueMarcela
C
10

Replacing: smtp.gmail.com with 173.194.65.108 actually worked for me!

Conaway answered 18/1, 2015 at 20:21 Comment(1)
Or replace smtp.gmail.com by gmail-smtp-msa.l.google.com. This domain have been found by ping smtp.gmail.com to recover the domain namePearce
I
3

If you ever want to return to using Gmail, I've just faced the same problem - the code worked on my local machine but not on a real server - and think I've figured out what is causing it (at least in my case).

It appears that if a server supports IPv6 and IPv4, the server's domain resolves as its IPv6 version so PHP tries to connect to that. But I was finding that smtp.gmail.com did not respond, so after 30 seconds the script just gave up and timed out. You would think that PHP would try IPv4 after IPv6 failed, but no.

So when I swapped in the IPv4 address of smtp.gmail.com (got by ping-ing it), everything worked fine and the email sent. It's not ideal using an IP in place of a domain since it could change, but at least it saves digging up the rest of the server's floorboards :)

Infestation answered 28/11, 2014 at 23:39 Comment(1)
Just had the same problem (IPv6 resolving took too long) and found a solution here: community.rackspace.com/products/f/25/t/5110Bergwall
P
1

just add 74.125.130.108 smtp.gmail.com to server's hosts file

Ping answered 16/4, 2015 at 8:59 Comment(0)
P
1

For me the issue was i that I used tls encryption,here are the ports for TLS and SSL. Don`t forget to reboot after changing the env file.

smtp.gmail.com    ---    SSL       ---      465
smtp.gmail.com    ---   StartTLS ---   587

Also,you need to change the security of your google account

Pitching answered 23/4, 2017 at 14:39 Comment(0)
L
1

I've just had this issue and after immense search for the solution, it was all a matter of a security setting with my host (In this case Scaleway). I had to open security settings and enable outgoing SMTP.

Open "security groups" settings:

open Security settings

Latoya answered 16/3, 2019 at 22:47 Comment(0)
S
0

I have posted a workaround solution in Swiftmailer Gmail Connection timed out #110 where you can either use IPv4 or IPv6.

Summer answered 12/12, 2014 at 19:56 Comment(0)
I
0

Config working for me:

mailer_transport: gmail
mailer_host: smtp.gmail.com
mailer_user: [email protected]
mailer_password: my_pass
mailer_encryption: ssl
mailer_auth_mode: login
mailer_port: 465
Isobel answered 3/8, 2018 at 10:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.