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:
- A static IP address (or at least one that does not change very often)
- The MX record of your domain (the one that ends in mail.protection.outlook.com)
- An email address that exists in your M365 tenant
- 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_PORT: 25 DISCOURSE_SMTP_USER_NAME: DISCOURSE_SMTP_PASSWORD: DISCOURSE_SMTP_ENABLE_START_TLS: true # (optional, default true) DISCOURSE_SMTP_DOMAIN: <your domain> DISCOURSE_NOTIFICATION_EMAIL: <email address that should exist even as an alias> DISCOURSE_SMTP_AUTHENTICATION: none
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.