Ghost is running with docker-compose, on a Digital Ocean droplet. I have setup Mailgun and am loading in variables via .env all on par with the documentation. I use nginx (nginx-proxy-manager also via docker-compose) and Cloudflare for DNS+SSL. The Ghost webui loads fine on https, however emails are not sending.
Here is my docker-compose.yml file:
version: '3'
services:
ghost:
image: ghost:5
restart: always
ports:
- ${PORT_BLOG}:2368
environment:
database__client: mysql
database__connection__host: db
database__connection__database: blog_db
database__connection__user: db_user
database__connection__password: ${MYSQL_PASSWORD}
url: "https://blog.mydomain.com"
mail__transport: "${MAIL_TRANSPORT}"
mail__options__host: "${MAIL_HOST}"
mail__options__port: "${MAIL_PORT}"
mail__options__secureConnection: "${MAIL_SECURE_CONNECTION}"
mail__options__auth__user: "${MAIL_USER}"
mail__options__auth__pass: "${MAIL_PASSWORD}"
volumes:
- ./ghost:/var/lib/ghost/content
links:
- db
db:
image: mysql:8.0
restart: always
environment:
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
MYSQL_DATABASE: blog_db
MYSQL_USER: db_user
MYSQL_PASSWORD: ${MYSQL_PASSWORD}
cap_add:
- SYS_NICE
volumes:
- ./mysql:/var/lib/mysql
The problem: When users try to subscribe, the /send-magic-link is not working. The behavior is a 504 timeout for /send-magic-link inside the user’s web UI and email is never sent. When I run docker logs {container_id}
it says the /send-magic-link request was a 200 success (with 90006ms response time… so still seems like a timeout to me… but interesting they show differently).
When I use the same exact docker-compose.yml file on my local dev machine and point Cloudflare DNS to my dev machine, I can send emails fine! So I know Mailgun is fine and my .env settings are loading fine. Also, when I SSH into my Digital Ocean droplet, I can send SMTP emails via swaks, like this:
./swaks --auth \
--server smtp.mailgun.org \
--au postmaster@mail.mydomain.com \
--ap <omitted> \
--to testuser123@gmail.com \
--h-Subject: "Hello" \
--body 'Testing some Mailgun from SMTP!'
Since this^ works, I don’t think Digital Ocean is blocking SMTP emails (which was my first suspicion). However, I am still unsure why emails cannot send when hosted on Digital Ocean droplet. The behavior is easy to reproduce for me by having a new user attempt to subscribe and monitoring the /send-magic-link requests, but it also appears anytime emails are attempted to send they have the same 504 timeout behavior.
The Digital Ocean ufw firewall rules are set to allow in/out for ports 587, 465, 443, 80, 25, etc. I have also tried .env values for ${MAIL_SECURE_CONNECTION} to be set to true and false, and tried ${MAIL_PORT} as 587 and 465. No luck on any combination that I could find, unfortunately.
I’ve been jamming my head at the wall trying to resolve this, and I am wondering if anyone has ran into this before or has recommended steps to I could try to debug this further.
Any idea what I could try to fix this? Thank you in advance for taking a look