Deliverability

Connection refused #111 on SMTP port 587: how to fix it

Connection refused #111 on port 587 means your server's TCP connection never reached the SMTP host, so a firewall, security group or hosting policy is blocking outbound traffic. Test the port with openssl s_client, open egress, switch to port 2525 or 465, or send through the provider's HTTP API instead.

Sohail HussainSohail Hussain10 min read

Short answer

  • Error 111 means your server could not open a TCP connection to the SMTP host. Your login was never checked, so this is a network problem and not a credentials problem.
  • From the failing server, test ports 587, 2525 and 465 with nc or openssl, then switch to one that connects. SES has no 2525, so use 2587 or 465/2465 there.
  • If every SMTP port is blocked, send through the provider's HTTPS API on port 443. If you use Laravel, run php artisan config:clear after changing .env.

Your app log says Connection could not be established with host email-smtp.us-east-1.amazonaws.com [Connection refused #111], or it just times out. The same credentials work from your laptop. The failure happens on the EC2 instance, VPS or shared host, and it shows up with Mailgun in Laravel, Mandrill in PrestaShop and SES in Mautic.

Why it happens

#111 is the Linux errno ECONNREFUSED. Swift Mailer, the library behind older Laravel, Mautic and PrestaShop mail setups, prints the message in this format. Newer Laravel versions use Symfony Mailer, which words the error differently but fails for the same reason. It all happens before TLS, before AUTH and before any SMTP reply code. You will not see a 535 or 550, because the SMTP conversation never started.

Most common causes first:

  1. Your host or cloud provider filters outbound SMTP on port 587 (or all SMTP ports).
  2. A security group, network ACL, cloud firewall or OS firewall on your side blocks the egress.
  3. The hostname, region or port in the config is wrong, or it points at a local relay that is not running.
  4. The app is still using old settings because of cached config (Laravel) or a cached admin setting.
  5. The provider-side check: your IP is blocked at the provider. This is rare and the least likely cause. Rule out the first four before you suspect it.

Community threads about Mailgun on EC2, SES in Mautic and Mandrill in PrestaShop describe this pattern: it works locally and fails from the server. I could not find a single cause that explains every report, so test instead of guessing.

"Refused" and "timed out" point to slightly different places:

SymptomWhat it usually meansWhat to try
Connection refused (#111)Something rejected the connection, or nothing listens at that addressCheck hostname and port, then host firewall rules
Timed outPackets are silently dropped by a security group, ACL, cloud firewall or ISP filterCheck egress rules, then try another port
Works locally, fails on the serverThe block is on the server's networkTest from the server, not your laptop
Port 587 fails, 2525 worksYour network blocks 587Use 2525 (not on SES)
Every port failsOutbound SMTP is blocked entirelyUse the HTTPS API or ask the host

Step-by-step fixes

1. Test the ports from the failing server

Run these on the server that throws the error, not on your laptop. Swap in your provider's hostname.

# Is the port reachable at all? Test each port in turn.
for p in 587 2525 465; do
  echo "== port $p =="; nc -vz -w 5 smtp.mailgun.org "$p"
done

# STARTTLS handshake (ports 587 and 2525)
openssl s_client -starttls smtp -connect smtp.mailgun.org:587

# Implicit TLS (port 465)
openssl s_client -connect smtp.mailgun.org:465

# Rule out a DNS failure
getent hosts smtp.mailgun.org

A healthy STARTTLS test prints a certificate and then a 220 greeting. If nc hangs or says "Connection refused", the block sits between your server and the provider. If getent returns nothing, you have a resolver problem instead. telnet host 587 works in place of nc if that is what you have. On Windows, Test-NetConnection -Port 587 -ComputerName {smtp-host} does the same job.

Whichever port connects is the one to use.

2. Switch to a port your network allows

Which alternative ports exist depends on the provider. Check the current docs, because ports can change (as of November 2026):

ProviderPorts that workNotes
Amazon SES25, 587 or 2587 with STARTTLS; 465 or 2465 with TLS WrapperNo 2525. Use 2587 or 2465 as the alternates
Mailgun25, 465 (SSL/TLS), 587 (STARTTLS) and 2525Mailgun's help page notes that Google Compute Engine allows port 2525 for SMTP submission
Mandrill (Mailchimp Transactional)Check Mailchimp's current docsHost is smtp.mandrillapp.com; I did not verify the port list in this search

The SES list comes from AWS's page, which also says the SES SMTP endpoint requires all connections to be encrypted with TLS. For background on what each port is for, see the SMTP glossary entry and our post on SSL/TLS for SMTP. The AWS page is Connecting to an Amazon SES SMTP endpoint. Mailgun's is Where can I find my API keys and SMTP credentials.

Match the encryption setting to the port. STARTTLS (called TLS in many app screens) goes with 587, 2587 and 2525. SSL/TLS (implicit) goes with 465 and 2465. A wrong pairing gives a handshake error instead of 111, which tells you the network block is gone.

EC2 and port 25

Amazon EC2 throttles outbound port 25 by default, but that does not explain a refused 587. If 587 fails from EC2, look at security groups, ACLs and the OS firewall next. The port 25 removal request will not help.

3. Check egress rules on your side

A default AWS security group allows all outbound traffic, but hardened setups often remove that rule. Check three places:

  1. Open the instance's security group and look at Outbound rules. They must allow TCP to the SMTP port you chose.
  2. Open the subnet's network ACL. ACLs are stateless, so you need an outbound rule for the SMTP port and an inbound rule for ephemeral ports (1024-65535) so replies get back.
  3. On the server, run iptables -L OUTPUT -n or ufw status and look for a reject or drop on that port.

An instance in a private subnet also needs a NAT gateway (or, for SES, a VPC endpoint) to reach the internet. AWS's VPC endpoint guide says SMTP endpoints can use ports 465, 587, 2465 or 2587, and API endpoints use port 443.

4. Check the hostname, region and relay

If nc fails on every port, check the host itself. SES SMTP endpoints are per region, and your SMTP credentials are tied to the region where you created them. A typo, a stale hostname, or localhost left in the config gives "refused" immediately, because nothing is listening there. Also confirm the config is not still pointing at a local Postfix that is not running (systemctl status postfix).

5. Clear cached config (Laravel)

You changed .env, but the app still dials the old host or port. If you ever ran php artisan config:cache, Laravel does not read .env at runtime until you clear and rebuild the cache.

php artisan config:clear
php artisan config:cache
php artisan queue:restart

Restart PHP-FPM too. Long-running queue workers keep the old config in memory until restarted. Then set the port. For Mailgun when 587 is blocked:

MAIL_MAILER=smtp
MAIL_HOST=smtp.mailgun.org
MAIL_PORT=2525
MAIL_ENCRYPTION=tls

For SES use MAIL_PORT=2587 and tls. For port 465 or 2465 use ssl. Newer Laravel versions pick the TLS mode from the port or a MAIL_SCHEME setting, so check your version's mail docs if the handshake fails after the port change.

6. Change the port in PrestaShop, Mautic and similar apps

These apps keep SMTP settings in the database or an admin screen, not a file. Change the port in the admin (in Mautic, the email settings under configuration; in PrestaShop, the mail or Mandrill module settings), then clear the app cache. Match the encryption to the port as described above.

7. Use the HTTPS API when no SMTP port works

Some hosts block every outbound SMTP port. Then stop fighting it. SES, Mailgun and Mandrill all offer an HTTPS API on port 443, which hosts almost never block. Laravel ships Mailgun and SES drivers. For Mautic and PrestaShop, check whether your version has a transport or module for the API. The trade-off is an API key instead of an SMTP login, plus slightly different config. Our email API and webhooks guide covers the differences.

Test where it matters

Run connectivity tests from the production network during setup, not only from your laptop. A port that works at home tells you nothing about the datacenter.

Checklist before you try again

  • You ran the port test from the failing server, not from your own machine.
  • The hostname matches your provider and region.
  • The port and the encryption mode belong together (STARTTLS or implicit TLS).
  • The security group, network ACL and OS firewall all allow outbound TCP on that port.
  • You cleared and rebuilt config caches and restarted PHP-FPM and queue workers.
  • Your provider's docs list the port you picked.

If nothing works

Open a ticket with your host first, because they control the network. If only one provider fails while others connect, send the same details to that provider and ask whether your IP is blocked on their side. Include:

  • the server's public IP
  • the destination hostname and port
  • the exact error text with a timestamp
  • the output of nc -vz and openssl s_client
  • the ports and the API route you already tried
Subject: Outbound SMTP connection refused from {server IP}

Hello,

Our server at {public IP} cannot open a TCP connection to {smtp host} on
ports 587, 2525 and 465. Error from the application at {timestamp UTC}:
"Connection could not be established with host {smtp host} [Connection refused #111]".

Attached: output of nc -vz and openssl s_client for each port, run from the
server. Security group and firewall egress rules allow these ports.

Is outbound SMTP filtered or restricted on this account or network? If so,
can it be lifted, or which port or relay do you recommend instead?

Thank you

Common questions

Why does it work on my laptop but not on the server?

Your home or office network allows outbound SMTP, and the server's network does not. Cloud and hosting providers often restrict it to fight spam. The credentials and the code are probably fine.

Is "Connection refused" different from "Connection timed out"?

Slightly. A timeout usually means packets are dropped silently by a firewall or filter. A refusal means something answered with a reset, or nothing listens at that address. The fix is the same: test from the server and try another port. I would not read much more into the difference.

Can I just use port 25?

I would not. Port 25 is the one most hosts restrict first, and AWS notes that EC2 throttles email traffic over port 25 by default. Ports 587 and 465 are the submission ports for authenticated sending.

Do I need to change my SPF or DKIM records after changing ports?

No. The port only affects how your app reaches the provider. Authentication records depend on the sending domain and the provider, not the port. Once mail flows, you can check them with the free email header analyzer and SPF generator.

deliverabilitymailgunmandrill-mailchimpamazon-seserror-codes
Share this article
Sohail Hussain

Sohail Hussain

Founder & CEO at Mailneo

Building Mailneo — AI-powered email marketing for growing businesses.

Related Articles

Deliverability

SES "Email address is not verified" but it shows verified

Amazon SES returns "Email address is not verified" when the identity isn't verified in the region your code calls. Identities are per region, so compare the region in the error, the SDK client and the console, then verify the identity there or change the client's region.

Sohail Hussain|9 min read
Deliverability

Amazon SES production access denied: how to get approved

When Amazon SES denies production access with "reasons cannot be provided due to security reasons", reply on the same support case with specifics: use case, list source and consent, bounce and complaint handling through SNS, opt-out method, and a sample email. Ask for a second review. If that fails, use another sender.

Sohail Hussain|9 min read
Deliverability

Apollo + Mailgun: "domain not on a Mailgun account" and IMAP

Apollo shows a "domain not being on a Mailgun account" error and asks for an IMAP host because Mailgun is a transactional sending service with no mailboxes. Verify the domain in Mailgun if you send by API; for sequences that need replies, connect a Gmail, Outlook or SMTP+IMAP mailbox instead.

Sohail Hussain|8 min read
Deliverability

DMARC Fails When SPF and DKIM Pass: Fix Alignment (550 5.7.23)

DMARC needs SPF or DKIM to pass and the passing domain to match your visible From domain. When both pass for a different domain (a vendor's bounce domain, a Mailgun subdomain), DMARC still fails. Sign DKIM with your From domain; one aligned DKIM signature is enough.

Sohail Hussain|9 min read

Ready to supercharge your email marketing?

Start sending smarter emails with AI-powered campaigns. No credit card required.

Get Started Free