Email newsletter with mailgun

When I try sending an email I get this error message:
Error sending mail, please check your Mailgun configuration

Is there anything I need to do from the end of mailgun, or is just a matter of putting in my email, sending domain and key?

And is the public key or the private key I should be putting there (I have tried both)

Thanks!

If you’ve not already, you’ll need to follow the steps written up here on how to configure Ghost with Mailgun:

Hi David,
Thanks for replying. I have already done this, and I am able to send test emails. Not real emails through the labs interface. When trying to send a test for a draft post, it does not work though.

Are you saying you are, or are not, able to send a test email using the test email option on the Labs page? If that isn’t working then you may have it configured incorrectly

I am able to send test emails using the Labs interface.

Not using a draft post though: “Error sending mail, please check your Mailgun configuration”

And presumably not with a new post.

Is this on a working draft that you have now? Could you try creating a new test draft and try sending a test? Thanks :slight_smile:

I just made a new draft post and tried to send an email test again and it didn’t work.

Just checked about the Labs email test option and that isn’t related to the members beta feature. Meaning this must be a Mailgun configuration issue. Probably wise to check over your setup and sure everything has been entered correctly :slight_smile:

But I can send a test email through labs, just not through the post. Shouldn’t a mailgun configuration issue have stopped that?

I also didn’t install ghost 3 from scratch, but rather I upgraded it. Would that had made a difference?

The Labs option you’re clicking is designed to test whether Ghost can send an email like a new user email. The beta Members feature is designed to send to send lots of emails, which is why it needs a service like Mailgun to handle the possibility of sending a lot of emails.

Oh I see, thanks for the clarification!

When you say a mailgun configuration issue, you mean the mailgun info entered into Ghost. Or do you mean something from on the side of mailgun.

Is there anything special I need to know about configuring mailgun? Which key should I put in the public or private? And is there anything I have to do from the mailgun side? And if I have more than one list, how does ghost know which list to send to?

  1. You need to put the private API key. The public key is for email validation which is another thing.
  2. The easiest way to find out you’ve configured Mailgun correctly is seeing if the records are checked off in “Domain settings > DNS records”
2 Likes

Thanks for this!

If mailgun works (I sent emails with it weekly) it means it is configured correctly? As in, there’s nothing special I have to do on the mailgun end to get it to play nicely with ghost?

I have the same issue, I can’t send test email through post but test email through Labs works.

Email failed to send when publishing this post. Please check your Mailgun configuration if the error persists.

Error: Cannot read property ‘toJSON’ of null

Did you check the replies above?

Yes I checked, I don’t know why is refuse to send test newsletter emails, BTW I use Mailgun EU addresses and I am hosted at DigitalOcean.

I have JUST gone through getting this setup with Mail Gun on Digital Ocean today.

This is what I did

  • setup ghost
  • setup mail gun
    — This includes setting up a custom domain on a paid plan and validating in. It isn’t REALLY a paid plan unless you send tons.
  • create NEW SMTP details on mail gun for the new custom domain (my website)
  • edit the ghost config file to have the SMTP details

I had done all this and was having the same problems with the TEST working but the POST TEST when creating a post NOT working.

I realised that I had entered the API key from Mailgun that I got for the sandbox domain when I first registered. So I went to my custom domain on mail gun, went to my API page, got the correct API key, pasted that key in the Ghost admin page for members and then the POST TEST worked as expected.

So if you have the main mail gun ‘test’ working in the admin, then certainly your issue is the wrong API key in the admin.

1 Like

That said. If this is your error then make sure you have actually entered a title and some content into the post you want to send. If there is nothing it will be submitting a null value to the test.

I tested with a lot of combinations of posts with titles, content, images/no images @fimo, and all the settings are correct API keys etc.

Check the log below for some reason can’t understand the Mailgun EU domain name.

 level: normal

"The email service was unable to send an email batch."
InternalServerError: The server has encountered an error.
    at new GhostError (/var/www/ghost/versions/3.13.3/core/server/lib/common/err                                                                 ors.js:10:26)
    at mailgunInstance.messages.send (/var/www/ghost/versions/3.13.3/core/server                                                                 /services/bulk-email/index.js:104:42)
    at Request.callback (/var/www/ghost/versions/3.13.3/node_modules/async/dist/                                                                 async.js:4617:26)
    at IncomingMessage.res.on (/var/www/ghost/versions/3.13.3/node_modules/mailg                                                                 un-js/lib/request.js:331:19)
    at IncomingMessage.emit (events.js:203:15)
    at IncomingMessage.EventEmitter.emit (domain.js:448:20)
    at endReadableNT (_stream_readable.js:1145:12)
    at process._tickCallback (internal/process/next_tick.js:63:19)

Error: Domain not found: smtp.eu.mailgun.org
    at IncomingMessage.res.on (/var/www/ghost/versions/3.13.3/node_modules/mailg                                                                 un-js/lib/request.js:327:17)
    at IncomingMessage.emit (events.js:203:15)
    at IncomingMessage.EventEmitter.emit (domain.js:448:20)
    at endReadableNT (_stream_readable.js:1145:12)
    at process._tickCallback (internal/process/next_tick.js:63:19)

[2020-04-16 16:57:52] ERROR "POST /ghost/api/v3/admin/email_preview/posts/5e9737                                                                 2e72fd120ed2d4574d/" 500 1405ms

NAME: EmailError
MESSAGE: Domain not found: smtp.eu.mailgun.org

Sorry - so, I deleted my replies as realised incorrect.

New question: how did you setup on Digital Ocean. Did you use the ghost package on the digital ocean marketplace or do it all from scratch?