Setup a self-hosted Ghost Blog with Docker and Caddy
Setup a self-hosted Ghost Blog with Docker and Caddy

Ghost blogging forum is simple to blog but kind of a pain to setup email. Here we are going to setup Ghost using a docker-compose.yml file with Caddy as the proxy.
The basic steps are outline here on Ghost documentation
Here are a couple of tips beyond this documentation. First the caddy file can be setup to do wildcard domains to secure HTTPS with Let's Encrypt.
Now the fun part, SMTP. So for signup and subscribes these are known in the SMTP world as transactional emails or basically one mail message to one user. You can do this by using Mailtrap free tier or even your Google Gmail. The difference between the two is Google will have a different domain sent then your blog so you will like have those emails show up as spam. Mailtrap will show it coming from your domain but you now have to signup for another service.
The second issue is Newsletters. In the SMTP world these are bulk emails. One message to many users. There are other SMTP services other than MailTrap but if you read the fine print, some don't allow transactional emails and can cut you off for terms of service violation.
If you want to use a 3rd party SMTP service and have a low-volume blog you can use Mailgun free tier and once you setup your service with Mailgun, you need to edit config.production.json and add the mail section.
{
"mail": {
"transport": "SMTP",
"logger": true,
"options": {
"service": "Mailgun",
"secureConnection": false,
"auth": {
"user": "<mailgun smtp user>",
"pass": "<mailgun smtp password>"
}
}
},
}
The other option is if you don't care about sending email via gmail you need a Google account with 2FA enabled.
Everything you need is your email and dedicated app password (for security reasons).
To generate this password :
- Go to https://myaccount.google.com/apppasswords
- Enter your regular password from your Google account (this is security settings)
- Select app, choose Other, and put the name (i.e SMTP)
- Now copy your password and write it down (you will have no chance to see it for the second time here)
Now, to setup SMTP for your Ghost:
- Go to your project directory
cd /var/www/ghost
- Open to edit your
config.production.json
- Copy and paste config object for
mail
and filluser
andpass
with your creds
"mail": {
"transport": "SMTP",
"options": {
"service": "Google",
"host": "smtp.gmail.com",
"port": 587,
"auth": {
"user": "your@google.email",
"pass": "this password"
}
}
},
You could burn down the paper with this password .
As a result, all your transactional emails should work fine without any additional pain in the ass. For example, now you could invite somebody else as a content contributor to your website.
Originally published on How to setup basic SMTP for Ghost - DEV Community