How to Configure Mailgun for Email in Ghost CMS
When running a self-hosted blog using Ghost CMS, email functionality is required for several core features. Ghost uses email to send login links, password reset messages, staff invitations, and system notifications. Without a properly configured mail service, administrators may see errors such as “Cannot send email. Check site configuration.”
One of the most reliable ways to enable email delivery in Ghost is by using Mailgun, a transactional email service designed for developers and web applications. This guide walks through the complete process of connecting Mailgun with a Ghost installation hosted on a VPS.
Why Ghost Requires Email Configuration
Ghost relies on email for authentication and communication features. Unlike many CMS platforms that rely primarily on password-based login, Ghost frequently uses magic login links delivered by email. Because of this design, configuring an SMTP provider is essential for proper operation.
Using a transactional email provider such as Mailgun ensures reliable delivery, proper authentication through SPF and DKIM, and better inbox placement compared to basic SMTP servers.
Step 1: Create a Mailgun Account
Begin by creating an account with Mailgun.
- Visit the Mailgun website and create a new account.
- Verify your email address and complete the onboarding process.
- After logging in, navigate to the Sending → Domains section.
Mailgun requires you to add a sending domain that will be used for outgoing emails.
Step 2: Add a Sending Domain
Instead of using your main domain directly, it is recommended to create a subdomain specifically for email sending.
Example domain structure:
mg.yourdomain.com
Using a dedicated subdomain protects the reputation of your main website domain and keeps transactional email traffic separated from web traffic.
When adding the domain in Mailgun:
- Domain name:
mg.yourdomain.com - IP assignment: Shared IP
- Region: Choose the closest region to your server
After adding the domain, Mailgun will generate several DNS records that must be added to your domain provider.
Step 3: Configure DNS Records
Mailgun requires a few DNS records for verification and authentication. These records usually include:
SPF Record (TXT)
Allows Mailgun servers to send emails on behalf of your domain.
v=spf1 include:mailgun.org ~all
DKIM Record (TXT)
Used for cryptographic email signing to verify authenticity.
k=rsa; p=LONG_PUBLIC_KEY
MX Records
Used for receiving and routing messages.
mxa.mailgun.org
mxb.mailgun.org
Tracking CNAME
email.mg.yourdomain.com
Add these records to your DNS provider (such as Hostinger, Cloudflare, or GoDaddy). After the records propagate, return to Mailgun and click Verify DNS. Once verified, the domain becomes active for sending emails.
Step 4: Obtain Mailgun SMTP Credentials
After domain verification, navigate to:
Sending → Domains → Your Domain → SMTP Credentials
Mailgun provides SMTP details similar to the following:
SMTP Host: smtp.mailgun.org
Port: 587
Username: postmaster@mg.yourdomain.com
Password: your_generated_password
These credentials will be used in the Ghost configuration file.
Step 5: Update Ghost Configuration
Log in to your VPS through SSH and navigate to your Ghost installation directory.
cd /var/www/ghost
Open the production configuration file:
nano config.production.json
Add the following mail configuration block inside the JSON structure.
"mail": {
"transport": "SMTP",
"from": "Ghost Blog <noreply@mg.yourdomain.com>",
"options": {
"host": "smtp.mailgun.org",
"port": 587,
"auth": {
"user": "postmaster@mg.yourdomain.com",
"pass": "MAILGUN_SMTP_PASSWORD"
}
}
}
Replace the SMTP username and password with the credentials obtained from Mailgun.
Save the file and exit the editor.
Step 6: Restart Ghost
After updating the configuration, restart the Ghost service to apply the changes.
ghost restart
This reloads the configuration and activates the new mail settings.
Step 7: Test Email Delivery
To verify that everything is working correctly:
- Visit the Ghost admin panel.
- Log out of the current session.
- Attempt to log in again using your email address.
Ghost should send a login link to your email inbox. If the message arrives successfully, the Mailgun integration is working correctly.
Common Troubleshooting Tips
If emails are not being delivered, consider checking the following:
- Confirm that Mailgun shows the domain status as Verified.
- Ensure DNS records were entered exactly as provided.
- Verify that the SMTP password in the Ghost configuration file is correct.
- Restart Ghost after any configuration changes.
Mailgun’s dashboard also includes email logs that can help diagnose delivery problems.
Conclusion
Configuring Mailgun with Ghost provides a reliable and scalable solution for sending transactional emails. Once connected, Ghost can send authentication links, password resets, and system notifications without interruption.
For production blogs hosted on VPS servers, using a dedicated email service like Mailgun ensures better deliverability, improved security, and a more stable blogging environment.