Setting up your Mailgun in your selfhosted Ghost
If you're hosting your own Ghost blog in a docker container you should to know how to setting up your mail settings with Mailgun, if not I will show you how π
In previous posts about Ghost I talked about how to create your own self hosted blog with Ghost blog:
And I show you how easy is upgrade your Ghost Docker instance to latest version:
Now I will show you how to setting up your Mailgun account to send emails in your blog.
TL;DR
Do you have a Ghost blog in a Docker container, and do you need to setting up the emails with Mailgun? i will show you how to do it here!
What is Mailgun π€
Mailgun is a platform that enables you to send, track, and optimize emails effortlessly (it is for free and offers up to 5000 mails per month), perfect companion for you blog.
Prerequisites π
- Mailgun API key it is given to you once you create your Sending domain.
- SMTP credentials, in Mailgun > Domain settings > SMPT credentials
Add credentials to Ghost in your Docker container
You should to add your Mailgun SMTP credentials to your config.production.json
this file will be located in your docker container at /var/lib/ghost/config.production.json
you could do it manually by copying the file inside the container with docker cp
the copy command provided by docker for this purpose, if you are looking for this kind of solution it looks like:
cp config.production.json <blog_ghost_container_id>:/var/lib/ghost/config.production.json
This works but it is not great as every time you stop your container the file will lost, given the nature of containers.
So let's include this command in your docker-compose file to do it automatically for you each time you run a docker-compose up
π
Lets add a Dockerfile
that will copy the file for us:
FROM ghost:5.79.4
WORKDIR /var/lib/ghost
COPY config.production.json ./
now lets modify your docker-compose
file to build the image from Dockerfile:
version: '3.1'
services:
ghost:
image: ghost:5.79.4
# this line make the image be build from Dockerfile
build: ./
restart: always
ports:
- 8080:2368
volumes:
- ghost-data:/var/lib/ghost/content
environment:
# see https://ghost.org/docs/config/#configuration-options
database__client: mysql
database__connection__host: db
database__connection__user: root
database__connection__password: ${MYSQL_PWD}
database__connection__database: ghost
url: https://blog.nicoandres.dev
db:
image: mysql:8.0
restart: always
environment:
MYSQL_ROOT_PASSWORD: ${MYSQL_PWD}
volumes:
- db-data:/var/lib/mysql
volumes:
ghost-data:
db-data:
With the new build:
section you are telling to docker to build the image first, so now you need to run docker-compose up -d --build
and your config.production.json
will be ready for let you send emails π§ π
Sources
- Ghost docs mail section:
Comments ()