Mailgun configuration works on local but not on production for /send-magic-link

The API request /send-magic-link stays pending for a long time and returns 504 by Nginx due to timeout.

This was the Mail config I added in ./config.production.json which was present at the root.

"mail": {
    "from": "'Sivanesh Shanmugam' <info@sivanesh.dev>",
    "transport": "SMTP",
    "options": {
      "service": "Mailgun",
      "host": "smtp.mailgun.org",
      "port": 465,
      "secure": true,
      "auth": {
        "user": "postmaster@sivanesh.dev",
        "pass": "<password>"
      }
    }
  }

Error in console

[2022-10-03 11:26:50] ERROR

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

level: normal

"Please see https://ghost.org/docs/config/#mail for instructions on configuring email."
Error: Connection timeout
    at createMailError (/var/www/sivanesh-ghost/versions/5.17.0/core/server/services/mail/GhostMailer.js:67:12)
    at SMTPConnection._formatError (/var/www/sivanesh-ghost/versions/5.17.0/node_modules/nodemailer/lib/smtp-connection/index.js:787:19)
    at SMTPConnection._onError (/var/www/sivanesh-ghost/versions/5.17.0/node_modules/nodemailer/lib/smtp-connection/index.js:773:20)
    at Timeout.<anonymous> (/var/www/sivanesh-ghost/versions/5.17.0/node_modules/nodemailer/lib/smtp-connection/index.js:232:22)
    at listOnTimeout (node:internal/timers:559:17)
    at processTimers (node:internal/timers:502:7)

What did I miss?

And

  • Installed and configured in a Linode VPS Ubuntu.

  • Node 16.17.1, Mysql, Ubuntu Server, Tested in Chrome

  • In local, the mail sending process is perfectly fine with the same config.

  • To reproduce click subscribe and try to signup by entering the username and password.

Your config is incorrect. Try this.


  "mail": {
    "from": "<email>",
    "transport": "SMTP",
    "options": {
      "host": "smtp.mailgun.org",
      "port": 587,
      "service": "Mailgun",
      "secure": false,
      "requireTLS": true,
      "auth": {
        "user": "<email>",
        "pass": "<password>"
      }
    }
  },

Hey @mjw, Thanks for the quick reply. But still getting the same error. API is pending for 1 minute. And then 504

Same error message

[2022-10-03 13:18:04] INFO "GET /assets/built/main.min.js.map" 200 15ms
[2022-10-03 13:19:12] INFO "POST /members/api/send-magic-link/" 200 60034ms
[2022-10-03 13:19:47] ERROR

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

level: normal

"Please see https://ghost.org/docs/config/#mail for instructions on configuring email."
Error: Connection timeout
    at createMailError (/var/www/sivanesh-ghost/versions/5.17.0/core/server/services/mail/GhostMailer.js:67:12)
    at SMTPConnection._formatError (/var/www/sivanesh-ghost/versions/5.17.0/node_modules/nodemailer/lib/smtp-connection/index.js:787:19)
    at SMTPConnection._onError (/var/www/sivanesh-ghost/versions/5.17.0/node_modules/nodemailer/lib/smtp-connection/index.js:773:20)
    at Timeout.<anonymous> (/var/www/sivanesh-ghost/versions/5.17.0/node_modules/nodemailer/lib/smtp-connection/index.js:232:22)
    at listOnTimeout (node:internal/timers:559:17)
    at processTimers (node:internal/timers:502:7)

Tested bulk emails. They are working fine. Only transaction emails are not working.

Have you opened the relevant ports? Evidently, your Ghost instance cannot connect to the mail server.

Yeah Opened them as well still the same results for transactional emails.

I tried Gmail as a mail client as well. But still facing the same issue. So I think the problem is not on the email service integration.

Are you using Linode? They block common SMTP egress ports… other hosts may do the same.

1 Like

Thanks a lot @mjw! The issue was the exact one as you said. Raised a ticket. They opened the ports and it works fine right now.

I’m pretty new to all these. So, It was almost a week for me working on this one thing. Once again thanks a lot for your support! You made my day!

1 Like