Thumbnail

How to Easily Handle "Forgot Password" Emails in Self-Hosted Ghost CMS Using Mailgun's Free Tier

2024-03-16

||

3 mins read

Looking to integrate Mailgun with your Ghost CMS for newsletters? You'll need the Mailgun Foundation plan. Get started here.

Integrating Mailgun with Self-Hosted Ghost CMS can be a great way to simplify your email sending process.Before you begin, make sure you have a Mailgun account and access to your Ghost admin panel.

Step 1: Set Up the Sandbox Domain

In the dashboard, locate the "Domains" section and select the Sandbox Domain. Here, you'll find a pre-configured sandbox domain provided by Mailgun.

domains  page in mailgun

Step 2: Add Authorized Recipient

You need to add an authorized recipient to the sandbox domain. This recipient will be the address where the password reset links will be sent. In the dashboard, navigate to "Authorized Recipients" under the sandbox domain settings and add the email address associated with your Ghost CMS admin account.

sandbox domain settings in mailgun page

Once you click "save recipient" a verification mail will be sent to your email to verify.

Step 3: Add Mailgun Domain and API Key to Ghost

Once you've added the DNS records, you'll need to go to your Ghost admin panel and select "Settings" and then "Mailgun settings".  

ghost admin page

Here, you can add your Mailgun domain and API key, which you can find in your Mailgun Dashboard.

mailgun api key page
mailgun settings in ghost

Click "Save".

Step 4: Create SMTP Credentials in Mailgun

To create SMTP credentials in Mailgun, select your domain in the Mailgun Dashboard and then click on "SMTP Credentials".

smtp credentials page

Click the "Add New SMTP Credential" button and give your credential a name.

Domain settings page in mailgun

Click "Create SMTP Credential" and copy the password that appears at the bottom right of the page. Paste the password in a notepad or other safe place.

Domain settings page in mailgun

Step 5: Add SMTP Credentials to Ghost

Finally, you'll need to ssh into Digital Ocean Container and change the user into ghost-mgr.

sudo -i -u ghost-mgr

Go to the ghost directory and open config.production.json

cd /var/www/ghost
vim config.production.json

In the file, change the value of mail with the following code.

Replace "your username" and "your password" with your Mailgun SMTP credentials.

"mail" : {
	"transport": "SMTP",
	"options": {
		"service": "Mailgun",
		"auth": {
			"user": "your username",
			"pass": "your password"
		}
	}
},
console of digital ocean container

After setting things up, to save the file press Esc and ":wq" and now we need to restart ghost for it to take these changes into account.

ghost restart
console of digital ocean container

Once you've completed these steps, you should be able to check your email sending capabilities by clicking "Forgot Password".