Mailgun emails 504 gateway timeout

If you’re looking for some help, it’s important to provide as much context as possible so that people are able to assist you. Try to always mention:

[2020-06-20 13:46:31] INFO "POST /blog/ghost/api/v3/admin/invites/" 200 60007ms
[2020-06-20 13:47:32] ERROR

NAME: EmailError
MESSAGE: Failed to send email. Reason: connect ETIMEDOUT 74.125.142.26:587.

level: normal

"Please see https://ghost.org/docs/concepts/config/#mail for instructions on configuring email."
EmailError: Failed to send email. Reason: connect ETIMEDOUT 74.125.142.26:587.
    at EmailError.GhostError (/var/www/ghost/versions/3.17.1/node_modules/@tryghost/errors/lib/errors.js:10:26)
    at new EmailError (/var/www/ghost/versions/3.17.1/node_modules/@tryghost/errors/lib/errors.js:34:20)
    at createMailError (/var/www/ghost/versions/3.17.1/core/server/services/mail/GhostMailer.js:51:12)
    at EventEmitter.<anonymous> (/var/www/ghost/versions/3.17.1/core/server/services/mail/GhostMailer.js:117:28)
    at Object.onceWrapper (events.js:286:20)
    at EventEmitter.emit (events.js:198:13)
    at EventEmitter.emit (domain.js:448:20)
    at DirectMailer.<anonymous> (/var/www/ghost/versions/3.17.1/node_modules/directmail/lib/mailer.js:185:42)
    at SMTPClient.<anonymous> (/var/www/ghost/versions/3.17.1/node_modules/directmail/lib/mailer.js:277:9)
    at Object.onceWrapper (events.js:286:20)
    at SMTPClient.emit (events.js:198:13)
    at SMTPClient.EventEmitter.emit (domain.js:448:20)
    at SMTPClient._onError (/var/www/ghost/versions/3.17.1/node_modules/simplesmtp/lib/client.js:373:10)
    at Socket.emit (events.js:198:13)
    at Socket.EventEmitter.emit (domain.js:448:20)
    at emitErrorNT (internal/streams/destroy.js:91:8)
    at emitErrorAndCloseNT (internal/streams/destroy.js:59:3)
    at process._tickCallback (internal/process/next_tick.js:63:19)

Why are you using port 587? I mean, if you have a valid reason for 587, have you opened this in your firewall?

I am using Mail Relay and the article mentions to ensure no SMTP ports are open.

I am able to send emails from relay server setup from above instructions. Log message

cgcom postfix/smtp[28526]: C645685470: to=<$myemailaddress$@gmail.com>, 
relay=smtp.mailgun.org[52.34.221.85]:587, delay=0.67, 
delays=0.09/0.04/0.19/0.35, dsn=2.0.0, 
status=sent (250 Great success)

From the error message of ghost logs
``` Reason: connect ETIMEDOUT 74.125.142.26:587``

I think the IP address is the issue more than the port because mail is successfully sent with Relay pointing mailgun IP as relay=smtp.mailgun.org[52.34.221.85]:587

Not sure if it would help if there is a way to reset this IP in ghost or nodemailer ?

1 Like

I got it to working by referring to this blog

One line change in config.production.json to get it to working:

"mail": {"transport": "sendmail", ......}

instead of “Direct” in transport

1 Like