Question

SMTP : Connection Refused

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.


Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

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.

Hello there

Our new disabled-by-default SMTP policy goes into effect today, June 22, 2022, for all new accounts. While our Security team will still be monitoring spam activity, we believe this decision will benefit our customers and the broader internet community in our shared quest to minimize spam.

https://www.digitalocean.com/blog/smtp-restricted-by-default

Regards

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

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