Question

SMTP : Connection Refused

Posted July 14, 2020 7.5k views
WordPressEmail

I currently am trying to connect to an external SMTP server so that I can send emails from a WP install using the WP Mail SMTP plugin. I’m not sure this is an issue from the hosting side here at DigitalOcean or from my email host but I’ve reached out to them and they said everything looks fine so I’m checking from this side.

Basically, I get the following debug output:

Connection: opening to ssl://mail.mysite.com:465, timeout=300, options=array ()

Connection failed. Error #2: stream_socket_client(): unable to connect to ssl://mail.mysite.com:465 (Connection refused) [/var/www/html/wp-includes/class-smtp.php line 298]

SMTP ERROR: Failed to connect to server: Connection refused (111)

During my testing I tried to run a Netcat from the DigitalOcean Droplet and get:

nc: connect to mail.mysite.com port 465 (tcp) failed: Connection refused

However, if I run it from my local machine I get:

Connection to mail.mysite.com 465 port [tcp/urd] succeeded!

So that lead me to think maybe I do have an issue from the DigitalOcean side? I’m not sure but any guidance would be greatly appreciated.

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
2 answers

Hi @theshowportal,

It does seem like you haven’t allow outgoing and incoming connections on port 465. You can do that by typing in the following rule on your droplet

sudo iptables -A INPUT -p tcp --dport 465 -m conntrack --ctstate NEW,ESTABLISHED -j ACCEPT
sudo iptables -A OUTPUT -p tcp --sport 465 -m conntrack --ctstate ESTABLISHED -j ACCEPT

Alternatively, I’ll recommend you to check some third party mail providers which actually provide you with a way to use their SMTP on your droplet. As they are made for such things as sending out emails and everything by default you shouldn’t have any issues with the mails. It would just be a matter of configuring your WP app.

Regards,
KFSys

  • Hi @KFSys,

    Thank you for that. I got word from support that they have blocked SMTP ports for spam protection and they couldn’t remove them for me.

    So I did like you suggested as an alternative and hooked up the WP app to an outside mail provider, MailGun. Thank you for that suggestion, was easy to do and seems to be working well.

    Best regards,
    Jake - theshowportal

Hello there,

What I could suggest here is using an SMTP plugin for your WordPress site.

That way you will be able to specify an SMTP server with authentication which your emails would be going through. You could for example use Gmail’s SMTP settings. This would drastically increase the delivery rate of your emails as well compared to using plain PHP mail.

I’ve been using this plugin for a while now and it works very well: Easy WP SMTP

https://www.digitalocean.com/community/tutorials/how-to-get-wordpress-email-notifications-on-a-digitalocean-droplet

Also make sure to use ports like 465 or 587 instead of 25

Hope that this helps!
Regards,
Alex

by Lyn Muldrow
Sending emails and notifications including form submit verifications and password resets from your WordPress server or Droplet is an essential function. In this tutorial, learn how to use a WordPress Simple Mail Transfer Protocol (SMTP) plugin to send emails from your WordPress Droplet or server.