Unable to set up Mailgun

I am unable to successfully set up Mailgun on my Digital Ocean droplet.

I have followed the SMTP settings, they are below, added the API key to my Mailgun settings, and I have set up the DNS settings needed. Still nothing works.

SMTP Settings:

"mail": {
    "from": "<email>",
    "transport": "SMTP",
    "options": {
      "service": "Mailgun",
      "auth": {
        "user": "<mailgun-email>",
        "pass": "password copied from Mailgun"
      }
    }
  }

I am at a total and complete loss what I am missing.

This config file is for transactional email only; bulk email and the API are setup in the Ghost admin interface.

To resolve the transactional email, amend the config as follows, and make sure egress ports are open on your Droplet.

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

I have updated the file to the following but it is still not working. I am using the US services so I don’t have the EU host. I know nothing about egress ports so maybe some help with that might be beneficial.

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

Actually, I posted the wrong clip. Change the port to 587 for StartTLS. That should work, but you may need to ask DO to open the port.

Incidentally, remove your email addresses from the post since these may be harvested by spambots.

Hey Jeff, I just set this up and got it working today. I’m also using DO.

I tried port 587, but it kept shutting me down. I had to change it back to 465 to get it to work. The tutorial I used is here (pics missing). The code for setting up mail in the config is only missing a comma after the user to be properly formatted JSON. Other than that, it should work just fine.

@jeffperry to make it even easier, this is what I followed:

"mail": {
        "transport": "SMTP",
        "options": {
            "service": "Mailgun",
            "host": "smtp.mailgun.org",
            "port": 465,
            "secureConnection": true,
            "auth": {
                "user": "postmaster@yourdomain.com"
                "pass": "your_password"
            }
        }
    },

So am I supposed to add a comma after the user or no?

I added the comma and I am still not getting it to work

The JSON should look like this:

"mail": {
        "transport": "SMTP",
        "options": {
            "service": "Mailgun",
            "host": "smtp.mailgun.org",
            "port": 465,
            "secureConnection": true,
            "auth": {
                "user": "postmaster@yourdomain.com",
                "pass": "your_password"
            }
        }
    },

Honestly, without the right formatting, I’m not sure that your Ghost restart after editing would work. If you want to check your JSON formatting, I’ve found JSONLint to be helpful.

I didn’t have to change anything on the Digital Ocean end (like opening up ports).

My formatting looks identical to this and I have had the instance where I had an invalid json format and I had to change it for Ghost to start properly.

I’m honestly at a loss because my code is correct. It’s so frustrating to see everything correct but nothing working.

Have you opened the ports in your firewall?

Also, please note that 465 is depreciated, and you should setup StartTLS instead (587).

I know it’s super frustrating. I quit Ghost twice because I couldn’t get it working. Hopefully, with a couple of us helping you, we’ll be able to figure it out.

  1. In Mailgun, did you get your domain verified, or are you using sandbox?
  2. What happens when you try to change the reply-to email address for your newsletter? Does it send out?

How should I do that?

Okay so I did that and bulk email works but transactional email is not working now (I am unable to change the email addresses for the newsletter and admin email in Ghost.

To open ports on the server, you’ll need to refer to the DO documentation.

This is handled by the API, not SMTP defined by the config.

Does this mean they were working? Please be clear, and confirm what you have done so far, including DNS, config etc.

Let’s get the basics working first.

Now my bulk email has stopped working, though transactional is fine. @mjw What ports do I need to open in the firewall?

Thanks!

What error messages are you seeing in Ghost and Mailgun? Have you tested the API from the command line?

curl -s --user 'api:YOUR_API_KEY' \
https://api.mailgun.net/v3/YOUR_DOMAIN_NAME/messages \
    -F from='Excited User <mailgun@YOUR_DOMAIN_NAME>' \
    -F to=YOU@YOUR_DOMAIN_NAME \
    -F to=bar@example.com \
    -F subject='Hello' \
    -F text='Testing some Mailgun awesomeness!'

The API uses either port 80 or 443, i.e., http(s).

Thanks Martin. The ports for the API are open. I can send preview emails to myself, but when I try to send a post, I get this error:

Uh-oh. Your post has been published but the email failed to send.

Email service is currently unavailable - please try again

Please verify your email settings if the error persists.

I tried the curl command, but got a message that was forbidden.

You need to get this working before attempting to send anything through Ghost.

Please post console output including the command, and redact API and email addresses. Make sure the credentials match that in Mailgun under sending / API.

Thanks, I was able to get the curl command to work.

“message”:“Queued. Thank you.”

I received the email at the address I specified.

What should I try next?

Double check credentials in Ghost, and then try a test mailing. Limit the number of recipients to 10 or fewer.

If you’re using a new domain, check that no rate limit is in place (you’ll need to contact Mailgun support.)