Thumbnail

How to Integrate Mailgun with Self-Hosted Ghost CMS for Easy Email Sending

2024-03-16

||

4 mins read

Integrating Mailgun with Self-Hosted Ghost CMS can be a great way to simplify your email sending process.You can quickly create and send eye-catching newsletters and email campaigns to your subscribers using Mailgun's robust email automation tools and Ghost's robust content management system.

Before you begin, make sure you have a Mailgun account and access to your Ghost admin panel, you'll also need a domain name and access to your DNS settings. When everything is ready, you can integrate Mailgun with your self-hosted Ghost CMS by following these detailed instructions.

Step 1: Add Your Domain to Mailgun Dashboard

To get started, log in to your Mailgun Dashboard and click on the "Domain" option in the side panel. From there, click the "Add Domain" button and enter your domain name. You'll need to select "2048" in the Advanced Settings and then click "Next."

dns settings for domain in mailgun

Mailgun will provide you with a set of DNS records that you need to add to your DNS settings.

dns settings of domain
dns settings of domain

Step 2: Add DNS Records to Your Domain

Next, you'll need to add the DNS records that Mailgun provided to your DNS settings. You can do this by logging in to your DNS settings and adding the records one by one.

Once you've added all the records, click "Verify DNS Settings" in the Mailgun Dashboard to confirm that they're set up correctly. It may take some time for the settings to update, so don't worry if you don't see green ticks right away.

domains page in mailgun

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".

Domain settings page in mailgun

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". If you encounter any issues, double-check your settings and refer to the Mailgun and Ghost documentation for further help.

You will need to have Mailgun Foundation subscription to send emails. If you want to setup mailgun for just "Forgot Password" you can do it with the free subscription by adding authorized user to mailgun sandbox domain.

In summary, integrating Mailgun with Self-Hosted Ghost CMS can help simplify your email sending process and improve your overall email marketing efforts. By following these simple steps, you can seamlessly integrate the two platforms and start sending beautiful and effective email campaigns to your subscribers.