"cannot connect to, port 587: Connection timed out"

Posted July 25, 2017 45.3k views
ApachePHPEmailDigitalOceanUbuntu 16.04Development


I tried this tutorial in order to enabling the email sending facility to the website which is on Droplets.

This worked fine in localhost and email sent/received very quickeley but it doesn’t work in Droplet.:(

This is the error message (when- tail /var/log/msmtp.log)

Jul 25 06:39:08 tls=on auth=on errormsg=‘cannot connect to, port 587: Connection timed out’ exitcode=EX_TEMPFAIL

Please help me :(


1 comment

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
3 answers

Hi @aleemfirnas22

If your account with DigitalOcean is new, then all SMTP actions are blocked and you need to create a ticket with Support via the control panel and ask to un-block SMTP.
This is to prevent SPAM.

  • Hi,

    Thanks @hansen I created a ticket as you suggested, could enabled mail-related traffic to my account.

    This is the tutorial I followed tutorial link , worked in local machine, now again the same problem persists. After clicked on the send button in the form from ( it’s loading some time but not recieved the email.

    Here is the php.ini settings in droplet

    [mail function]
    ; For Win32 only.
    SMTP = localhost
    smtp_port = 25
    ; For Win32 only.
    ;sendmail_from =
    ; For Unix only.  You may supply arguments as well (default: "sendmail -t -i").
    sendmail_path = "/usr/bin/msmtp -C /etc/.msmtp_php --logfile /var/log/msmtp.log -a gmail -t"


    by Jesin A
    Read through this tutorial to learn how to use Gmail or Yahoo with PHP mail() function.


How did it work on localhost? What tutorial did you follow?

Make sure you’re connecting with it over IPv4, not IPv6. It seems like DO is blocking IPv6 SMTP traffic.

And for what it’s worth, you can test by connecting with Gmail’s servers with the following:
$ telnet 587

Then to test with IPv4:
$ telnet -4 587

If you see it trying to connect (and failing) with IPv6 with the former command, but succeeding with IPv4 in the latter command, you’ll need make your droplet use IPv4.