Using Mailgun for SFTP times out

If you’re looking for help, please provide information about your environment. If you delete this template and don’t provide any information, your topic will be automatically closed.

If you aren’t running the latest version of Ghost, the first thing we’ll ask you to do is update to the latest version of Ghost.

  • What’s your URL? Site not public
  • What version of Ghost are you using? 4.41.3

How was Ghost installed and configured?

Ghost is running with docker-compose on a Linode VPS, using the following configuration:

ghost-logs:
    image: ghost:4-alpine
    volumes:
      - ghost-log:/var/lib/ghost/content
    restart: always
    ports:
      - 3003:2368
    environment:
      # see https://ghost.org/docs/config/#configuration-options
      # this url value is just an example, and is likely wrong for your environ>
      url: "REDACTED"
      
      mail__transport: "SMTP"
      mail__options__service: "Mailgun"
      mail__options__host: "smtp.eu.mailgun.org"
      mail__options__port: 587
      mail__options__auth__user: "<REDACTED>"
      mailgun__auth__pass: "<REDACTED>"

What Node version, database, OS & browser are you using?

Node v14.19.1
Database: SQLite3
Browser: Orion 0.99.113.2-beta and Safari 15.4
OS: Debian 11 bullseye

What errors or information do you see in the console?

When trying to log in to a test account I made:

[2022-03-26 11:52:32] INFO Worker for job "update-check" online
[2022-03-26 11:52:34] INFO Worker for job update-check sent a message: Ran update check
[2022-03-26 11:52:34] INFO Worker for job update-check sent a message: done
[2022-03-26 11:52:51] INFO "GET /" 304 100ms
[2022-03-26 11:52:51] INFO "GET /members/api/member/" 204 2ms
[2022-03-26 11:52:51] INFO "GET /members/api/site/" 200 23ms
[2022-03-26 11:54:18] INFO Worker for job "email-analytics-fetch-latest" online
[2022-03-26 11:54:20] INFO Worker for job email-analytics-fetch-latest sent a message: Fetched 0 events and aggregated stats for 0 emails in 331ms
[2022-03-26 11:54:20] INFO Worker for job email-analytics-fetch-latest sent a message: done
[2022-03-26 11:54:32] INFO "POST /members/api/send-magic-link/" 200 60990ms
[2022-03-26 11:55:31] ERROR Failed to send email. Reason: Connection timeout.

Failed to send email. Reason: Connection timeout.

"Please see https://ghost.org/docs/config/#mail for instructions on configuring email."

Error ID:
    a35750a0-acfb-11ec-b7d2-e5202f57ba13

Error Code: 
    ETIMEDOUT

----------------------------------------

Error: Connection timeout
    at createMailError (/var/lib/ghost/versions/4.32.2/core/server/services/mail/GhostMailer.js:67:12)
    at SMTPConnection._formatError (/var/lib/ghost/versions/4.32.2/node_modules/nodemailer/lib/smtp-connection/index.js:784:19)
    at SMTPConnection._onError (/var/lib/ghost/versions/4.32.2/node_modules/nodemailer/lib/smtp-connection/index.js:770:20)
    at Timeout.<anonymous> (/var/lib/ghost/versions/4.32.2/node_modules/nodemailer/lib/smtp-connection/index.js:229:22)
    at listOnTimeout (internal/timers.js:557:17)
    at processTimers (internal/timers.js:500:7)

What steps could someone else take to reproduce the issue you’re having?

  • Add your Mailgun credentials to docker-compose through environment variables.
  • Create testing Member account
  • Try to log into that Member account
  • Check the console (docker-compose logs -f)

I have no idea how to even start debugging this. I’ve double-checked my credentials and checked that my mailing ports were open. I also tried using the default SFTP configuration (this is not ideal because of email reputation etc.), but that also resulted in an error (Failed to send email. Reason: Sending failed.).

Does anyone have any ideas?

This is what I ended up doing to fix it:

  • Make sure that your VPS provider doesn’t block mailing ports, and if they do, get them to unblock them.
  • Make sure that you have your mailing ports opened on an OS level (your OS firewall is usually separate from your cloud provider’s firewall). A good way to do this is using the ufw (Uncomplicated FireWall) utility. sudo ufw enable, then sudo ufw allow smtp to open the ports required for email.
  • Make sure you’re using smtp.eu.mailgun.org if you have an EU domain, or smtp.mailgun.org if you have a US domain.
  • You need to connect on port 465

If this doesn’t work, try manually allowing port 465 in UFW (sudo ufw allow 465)

This is the config that ended up working for me (under environment in docker-compose.yml:

mail__transport: SMTP
mail__options__service: Mailgun
mail__options__host: smtp.eu.mailgun.org # or smtp.mailgun.org if you're in the US
mail__options__port: 465
mail__options__auth__user: postmaster@yourdomain.com
mail__options__auth__pass: yourPassword