Ghost on Docker + Office 365 SMTP

Ghost on Docker + Office 365 SMTP

Here is how to get Ghost running in Docker to use Office 365 to send emails via SMTP

I wanted to do this, and there were no guides. This could also be adapted for a native install, just add the options to your config.production.json file using the official documentation as reference.

There are two ways to do this, via authenticated SMTP using Office 365's servers on port 587, or using Direct Send on port 25 from the server hosting Ghost. I pulled the Office 365 information from the official Microsoft documentation

Authenticated STMP

First you need an email address to send from. If you are just sending from your own email address, you can just enter that.

If you want a custom address, the easiest way to do this is to create a distribution list in Exchange, hide it from the address list and give your user send-as rights to that list. You can then enter your login with an app-password in the below config.

Just replace your from email with either your email, or your distro list. And then enter your credentials

-e mail__transport=SMTP \
-e [email protected] \
-e mail__options__service=O365 \
-e mail__options__host=smtp.office365.com \
-e mail__options__port=587 \
-e [email protected] \
-e mail__options__auth__pass=yourapppassword

Direct Send

Add the following environmental flags to your Ghost Docker instance, and restart it

You will need to change your endpoint name, and the from email. The from email can be anything within your domain, and does NOT need to have a mailbox.

-e mail__transport=SMTP \
-e [email protected] \
-e mail__options__service=O365 \
-e mail__options__host=your-endpoint-name.mail.protection.outlook.com \
-e mail__options__port=25 \

If you don't want all the emails to be marked as spam, you will need to update the SFP record with your DNS provider. Simply add the external IP where Ghost is hosted

v=spf1 ip4:<Ghost-ext-IP> include:spf.protection.outlook.com ~all

Once you have done that, try and send a test email. It should work