I signed up for a Mailgun account, put in my API key in the admin area and tested that a “signup/welcome” could be successfully sent to myself.
Days and weeks passed and I had no new subscribers, until I heard from someone that they never got the confirmation email. OH!
I confirmed Mailgun was set in the admin area and successfully tested getting the confirmation email myself. Here’s how I fixed it.
Mailgun has to be set up twice!
Eventually I found the details I needed in official docs but they are not as clear as they could be. While it’s reasonable to expect that setting up Mailgun in the admin area routes all emails through the service, that’s not the case. It only routes bulk email through there. Transaction emails, like confirmation links, have completely different configuration, which is in config.production.json
.
There I had to configure Ghost to send mail to Mailgun via SMTP using an SMTP Password which is different from the Mailgun API key used in the admin area. It would be great if Ghost would supporting using the API key for both cases.
Transactional mail configuration is covered here: Configuration - Adapt your publication to suit your needs
More evidence of users being confused by the duplicate Mailgun configuration requirement is here:
How Ghost could improve the self-hosting experience here
- Add the
nodemailer-mailgun-transport
module as a dependency. It supports sending through the Mailgun API using the API key and not the SMTP credentials: nodemailer-mailgun-transport - npm - Modify the transaction mail sending code a little. Check to see if the Mailgun API key exists in “settings”. If transaction email settings are empty (and possible if they are set to ‘direct’ and ‘sendmail’), then use the Mailgun API key from settings.