Deliverability

EmailError ETIMEDOUT in Ghost: Mailgun SMTP Timeout Fix

Ghost's "EmailError ETIMEDOUT ... Connection timeout" means your server could not open a TCP connection to the SMTP host in time. Newsletters go through the Mailgun API over HTTPS, so they still work. Test port 587 from the server, then open it, switch to port 2525, or fix DNS.

Sohail HussainSohail Hussain9 min read

Short answer

  • Ghost cannot open a TCP connection from your server to smtp.mailgun.org on the configured port (usually 587), so the connection times out before login even starts.
  • Run a port test from the Ghost server itself, then open outbound SMTP in the host firewall or cloud network rules, or switch the mail block to port 2525 or 465.
  • Newsletters still work because Ghost sends them through the Mailgun API over HTTPS, not SMTP.

You invite a staff user or request a member login link, the screen spins, and the Ghost log shows this:

EmailError CODE: ETIMEDOUT MESSAGE: Failed to send email. Reason: Connection timeout.

Meanwhile your newsletter sends through Mailgun without trouble. The two facts fit together, and the fix is almost always at the network level, not in your Mailgun account.

Why it happens

ETIMEDOUT is a Node.js network error: the TCP connection attempt got no reply before the timeout. A stack trace pointing at SMTPConnection (Ghost uses Nodemailer for transactional mail) means the failure happened while connecting, before any EHLO, STARTTLS or AUTH step. Your credentials have not been tested yet.

Causes, most common first:

  1. Outbound SMTP is blocked or dropped. Many cloud and VPS providers block outbound SMTP ports by default to fight spam. A silent drop produces a timeout rather than a refusal.
  2. A firewall rule on the server or in the cloud network. Host rules (iptables, nftables, UFW) or cloud egress rules (security groups, network security groups, VPC firewall rules) can restrict outbound traffic.
  3. Docker or proxy networking. A container's network can differ from the host's, and an outbound proxy or VPN may not pass SMTP.
  4. IPv6 routing problems. If the hostname resolves to an IPv6 address your server cannot route, the connection hangs.
  5. Wrong region host. A Mailgun domain created in the EU region uses smtp.eu.mailgun.org, not smtp.mailgun.org.

Why newsletters work but invites and logins fail

Ghost sends mail two ways. Bulk newsletters go through the Mailgun API over HTTPS (port 443), configured with your Mailgun domain and API key. Transactional mail (staff invites, password resets, member sign-in links, signup confirmations) goes through the mail block in your Ghost config, which is plain SMTP.

So outbound HTTPS is open while outbound SMTP is not. People on the Ghost community forum report exactly this pattern with a config pointing at smtp.mailgun.org:587.

How this differs from similar errors

What you seeWhat it meansWhere to look
ETIMEDOUT / "Connection timeout"No reply to the connection attemptFirewall, host policy, routing
ECONNREFUSEDThe host answered and refused the portWrong port or host
ENOTFOUNDDNS could not resolve the hostnameTypo in host, resolver
535 authentication failureConnection worked; login rejectedSMTP username and password

Step-by-step fixes

Fix 1: Test the port from the Ghost server

Run these on the server that hosts Ghost, not your laptop. A test from your laptop proves nothing about the server's network.

  1. Test port 587:

    nc -vz -w 10 smtp.mailgun.org 587
    
  2. If nc is not installed, use this instead:

    timeout 10 bash -c 'cat < /dev/null > /dev/tcp/smtp.mailgun.org/587' && echo open || echo blocked
    
  3. For a fuller check that shows the TLS handshake:

    openssl s_client -starttls smtp -connect smtp.mailgun.org:587 -crlf
    

    You want a 220 banner and a certificate. If it hangs, the port is blocked between your server and Mailgun.

  4. Repeat the test for ports 2525 and 465. Port 465 uses implicit TLS, so run openssl s_client -connect smtp.mailgun.org:465 without -starttls.

  5. Check DNS with getent hosts smtp.mailgun.org. It should return addresses; if it hangs or returns nothing, fix the resolver first.

Which ports succeed tells you what to configure.

Fix 2: Open outbound SMTP on the host

If 587 is blocked, check these places, nearest to the server first:

  1. Host firewall. UFW allows outbound by default, but run sudo ufw status verbose and look for deny (outgoing). Also check sudo iptables -S OUTPUT and sudo nft list ruleset for drops.
  2. Cloud egress rules. Review AWS security groups, Azure network security groups or Google Cloud firewall rules. Add an outbound rule for TCP 587 (or 2525).
  3. Provider policy. Some hosts block outbound SMTP by default, and you have to ask support to lift it. Say you are connecting to Mailgun's authenticated submission port from a Ghost site.
  4. Docker. If Ghost runs in a container, test from inside it with docker exec, because the container network can differ from the host's.

Test inside the container

If the host can reach Mailgun but Ghost still times out, the problem is usually the container network. Run the port test from inside the Ghost container before changing anything else.

Fix 3: Switch to a port your host allows

Mailgun's SMTP ports include 587 and 2525 (STARTTLS) and 465 (implicit TLS). Hosts that block 587 often leave 2525 or 465 open, though that varies, so go by your Fix 1 results. Edit the mail block in config.production.json in your Ghost install directory:

"mail": {
  "transport": "SMTP",
  "from": "Your Site <noreply@mg.example.com>",
  "options": {
    "host": "smtp.mailgun.org",
    "port": 2525,
    "secure": false,
    "auth": {
      "user": "postmaster@mg.example.com",
      "pass": "your-smtp-password"
    }
  }
}

For port 465, set "port": 465 and "secure": true. For 587 and 2525, keep "secure": false; Nodemailer upgrades the connection with STARTTLS. Then restart from the Ghost install directory:

ghost restart

Use the SMTP credentials from your Mailgun domain settings. If your Mailgun domain was created in the EU region, the host is smtp.eu.mailgun.org, so match it to your domain's region.

Fix 4: If every SMTP port times out

If all SMTP ports time out but HTTPS works, the block is at the network level and nothing in Ghost will change that. Your options:

  1. Ask the host to allow outbound SMTP.
  2. Move the server to a host that does not restrict it.
  3. Use an SMTP relay that accepts connections on a port your host leaves open.
  4. Check Ghost's mail documentation for the transports your version supports before changing transport type. I would not assume a Mailgun API transport exists for transactional mail in every version.

Fix 5: Rule out the less common causes

  1. IPv6. Test with nc -4 -vz smtp.mailgun.org 587. If IPv4 works and the default does not, fix IPv6 routing or disable it on the server.
  2. Wrong host. A misspelled hostname usually gives ENOTFOUND, but a name that resolves to a machine not listening on that port times out.
  3. Proxy or VPN. An outbound proxy that does not pass SMTP causes the same symptom.
  4. Intermittent timeouts. If the test sometimes works, suspect an overloaded server or a flaky network path, not a hard block. Retest several times.

Cause to fix at a glance

SymptomLikely causeFix
Port test hangs on 587, 2525 and 465Provider blocks outbound SMTPAsk host to lift it, or change host
587 hangs, 2525 or 465 opensPort-specific blockChange port (and secure for 465)
Works on host, fails in containerContainer networkFix Docker network or egress
Works with nc -4, hangs withoutIPv6 routingFix or disable IPv6
Connects, then 535Wrong SMTP loginCopy credentials from Mailgun

Checklist before you try again

  • The port test ran on the Ghost server (or inside its container), not your laptop.
  • getent hosts smtp.mailgun.org returns addresses.
  • The host matches your Mailgun region (smtp.mailgun.org or smtp.eu.mailgun.org).
  • secure is false for 587 and 2525, true for 465.
  • The SMTP user and password come from your Mailgun domain settings.
  • You ran ghost restart after editing config.production.json.

Confirm the fix

Trigger a real transactional email: invite a staff user in Ghost Admin, or request a password reset. Watch the log with ghost log. The error should disappear and the message should show up in Mailgun's logs for your domain. If it now fails with a 535 error, the connection is fixed and you only need the right SMTP username and password.

Once mail flows, make sure your sending domain has SPF and DKIM set up so login emails reach the inbox. Our SPF generator and guide to SPF, DKIM and DMARC cover that, and the email header analyzer helps if a test message lands in spam.

If nothing works

Contact your hosting provider if every SMTP port times out from the server while HTTPS works. Send them the nc output, the server's public IP and the destination smtp.mailgun.org. Contact Mailgun only once the connection succeeds but sending or authentication fails; include the timestamp, your sending domain and the exact SMTP response.

Subject: Outbound SMTP blocked from my server

Hello,

My server (public IP: {your-server-ip}) cannot open outbound
connections to smtp.mailgun.org on ports 587, 2525 and 465.
HTTPS to the same host works. Test output:

{paste nc or openssl output here}

Ghost logs: EmailError CODE: ETIMEDOUT MESSAGE: Failed to send
email. Reason: Connection timeout.

Please allow outbound SMTP (authenticated submission to Mailgun)
for this server, or tell me which port you permit.

Timestamp of last failure: {date and time, with timezone}

Common questions

Does Ghost need SMTP if I already use Mailgun for newsletters?

Yes. The Mailgun API settings only cover bulk newsletter sending. Staff invites, password resets and member sign-in links use the mail block in your Ghost config.

Is this a Mailgun outage?

Unlikely if newsletters send at the same time, since they use the same provider over HTTPS. A timeout that appears on all SMTP ports from your server points to your network, not Mailgun.

Will a wrong password cause ETIMEDOUT?

No. Bad credentials produce an authentication error such as 535 after the connection succeeds. A timeout means the connection never completed.

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

Your laptop is on a different network. Many server hosts block outbound SMTP while home and office networks allow it, so always test from the server.

deliverabilityghostmailgunerror-codes
Share this article
Sohail Hussain

Sohail Hussain

Founder & CEO at Mailneo

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

Related Articles

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

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 Hussain|10 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
Deliverability

Ghost "Something went wrong while checking this URL" (422) fix

Ghost shows "Something went wrong while checking this URL, please try again." with a 422 when you recommend a Substack homepage, because the page's metadata is added after load. Recommend an individual post URL from that Substack instead, then use the checks below if that fails too.

Sohail Hussain|7 min read

Ready to supercharge your email marketing?

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

Get Started Free