Discourse email setup with Exchange Online

Recently I migrated some services to another server and I did not want to use the particular IP to send emails out. As I already have an Office Microsoft 365 tenant I thought I could use Exchange Online as a relay.

A first thought was to get one more Exchange Online Plan 1 license and use the credentials for authentication by disabling the MFA for that particular user.

But, as the volume of the emails would be very low why pay? Not to mention that Discourse does not play well with 365 ever since MS deprecated basic authentication.

The setup is for the relay and the connector you need:

  1. A static IP address (or at least one that does not change very often)
  2. The MX record of your domain (the one that ends in mail.protection.outlook.com)
  3. An email address that exists in your M365 tenant 
  4. Access to your DNS zone so you can edit your SPF entry

The connector configuration is described in the Microsoft article under Option 3 on this link

Note 1 If your IP changes you can Edit the connector and the Edit sent Identity

Note 2. If your IP gets blacklisted you can use the DeList to remove it from the MS blacklist. It takes around 30 mins.

Note 3. Remember to add the ip address of your server to your spf entry in your zone and to update it if changed.

v=spf1 ip4:xxx.yyy.zzz.xyz include:spf.protection.outlook.com -all

Now that the connector is setup time to change the discourse email settings. Login on the server and

cd /var/discourse
sudo nano containers.yml

find the part related to SMTP and change it to

DISCOURSE_SMTP_ADDRESS: <your MX record that ends with.mail.protection.outlook.com>
DISCOURSE_SMTP_ENABLE_START_TLS: true           # (optional, default true)
DISCOURSE_NOTIFICATION_EMAIL: <email address that should exist even as an alias>

save, exit (CTRL+X followed by Y) and rebuild the app

./launcher rebuild app

It will take some time and when finished login on the discourse server as admin and test.

Leave a Reply

Your email address will not be published. Required fields are marked *