Outbound Email for Ghost Blog
Ghost is a modern, open source, decentralized by design blogging platform. Out of the box it has a 'subscribe' feature that requires the ability to send email confirmations (and updates) to your audience. So it needs to send email. How hard could that be?
Well, back in the old days, any old Internet connected server could send email anywhere, just by doing a DNS request for the MX of a recipient domain, and then initiating a connection on tcp/25 to the MX. These days, email deliverability is a high hurdle, and most mail won't get through unless you use an Email Service Provider like SendGrid, SES or Mailgun.
This post makes two assumptions: 1) that you're using Docker to run (self hosted) Ghost, and 2) that you've already followed the instructions in this post to setup an authenticated relayhost that will send email on your behalf via SendGrid.
So, let's get started. In this first example, we simply pass a few environment variables to Docker to tell Ghost how to connect to your Postfix relayhost:
#!/bin/bash
set -x
# smarthost config
docker run --rm -it --name ghost -e mail__transport=SMTP \
-e mail__options__host="smarthost" \
-e mail__options__port=25 \
-e url=https://blog.zanshindojo.org -p 2368:2368 -v ghost-data:/var/lib/ghost/content ghost
That's it! These env vars tell Docker to tell Ghost to use an SMTP server at hostname 'smarthost' on tcp/25. Of course your url, port, and volume parameters will vary.
Now that email is configured properly, the built-in subscription capability of Ghost (that fwiw cannot be disabled in settings) will be operational.
Note that if you want to use SendGrid directly, without a smarthost running on your network, modify your configuration as follows:
# sendgrid config
docker run --rm -it --name ghost -e mail__transport=SMTP \
-e mail__options__auth__user="apikey" \
-e mail__options__auth__pass="YOUR_SENDGRID_API_KEY" \
-e mail__options__host="smtp.sendgrid.net" \
-e mail__options__port=587 \
-e mail__options__secureConnection=true \
-e url=https://blog.zanshindojo.org -p 2368:2368 -v ghost-data:/var/lib/ghost/content ghost
That configuration will instruct Ghost to connect directly to SendGrid, instead of relaying via your smarthost. If you only need email capabilities for Ghost, and nothing else, use this configuration.