Mailgun 502 Bad Gateway

Hello -

I have my Ghost installation up and running on a DigitalOcean drop. Regularly configured, it works absolutely fine. However, I want to set up email via Mailgun.

I followed instructions via Mailgun/Ghost, verified my DNS settings, then went to update my config.production.json, replacing the default mail section with:

/`  "mail": {
    "transport": "SMTP",
    "options": {
      "service": "Mailgun",
      "host": "smtp.mailgun.org",
     "port": 587,
      "secureConnection": true,
      "auth": {
        "user": "my username",
        "pass": "my SMTP password",
      }
    }
  }`

When I access my website after rebooting Ghost, it gives me a 502 Bad Gateway error. Yet, when I revert these settings to default again, I can access my site. I tried validating the JSON and it came back okay. Any help is appreciated!

1 Like

did you have a comma after the final curly brace? Try adding that in and then do ghost restart

I did have a comma. Sorry it did not paste over!

I have been playing with the config file for the last 24 hours for a similar but different issue. Your code looks like it shouldn’t be throwing any Gateway errors. (On a side note I’m running the same mail gun code and I can’t get it to send email without errors)

Are you touching any of the other settings in the config file? Bad Gateway seems to be when the port is set wrongly or an instance isn’t running. Try just pasting the above code in and deleting the current mail directive.

Right! I appreciate your help. I’m not changing anything else other than the mail section. If I upload the exact same config but delete the mail directive, it loads my site fine.

I wish I could be more help. All I can say is that yours looks good.

I am close to giving up on my own issue right about now.

Whoa! You have a problem!!! The comma after the password should not be there! Fix that and you are good to go.

Oh wow that was it! So simple and overlooked it. Appreciate it. Wish I could help on your issue more but it’s over my head!

Glad to help! It makes me feel like I haven’t been wasting a beautiful Saturday on this.

I’m facing the same problem, it was only changing the configuration to use MailGun SMTP that Ghost started to return 502 Bad Gateway

"mail": {
    "transport": "SMTP",
    "options": {
      "service": "Mailgun",
      "host": "smtp.mailgun.org",
      "port": 465,
      "secureConnection": true,
      "auth": {
        "user": "SMTP_user",
        "pass": "SMTP_password"
      }
    }
  }

Although I only edited the block regarding the email settings, for some reason the nginx configuration was pointing to port 2368 while config.production.json was configured to run on port 2369.

I configured both to run on the same port and my website returned to working normally.