Office 365 SMTP settings

Hello. Just set up my first Discourse docker. Couldn’t get SMTP to work via Office 365 and have spent the afternoon debugging. Couldn’t find a related post so thought I’d share what I did.

According to this TechNet article third party applications need to have an exchange licence and login set up. Note that having ‘#’ in the password may cause issues when you fill out the app.yml file.

Then you need to setup an Exchange connector via the Exchange Admin Panel, from ‘Your Organisation Email Server’ to ‘Office 365’, and restrict it to your VM’s IP (as explained in the TN article)

Then once you have the licence assigned to your ‘noreply’ email account you need the following in your app.yml:

[edit: this was incorrect. See below for the right settings]

Hope this saves someone else a rainy Tuesday afternoon of rebuilds.

2 Likes

Are you sure the terms of service for office 365 allow this? Discourse can send potentially thousands of emails per hour on a busy instance.

For example, using Gmail for your outgoing Discourse mail service is absolutely prohibited by the Gmail terms of service. I would be quite shocked if this was not also the case for Outlook / Hotmail / Office365.

(For incoming mails, e.g. reply-by-mail it’s less of a big deal since the volumes are so low.)

Hi Jeff,

You have to buy a licence for the mailbox, otherwise it won’t work. I just added it to our company bill. It’s still being a little bit tricky tbh - will raise a support ticket with MS and update the thread once it’s reliable.

Matt
edit: removed email signature. Stupid phone.

OK so I heard back from MS support nice and quickly. I didn’t have the settings correct. I’m a mechanical engineer by training so correct me if my terminology is wonky.

From the top:

You need a mailbox licence for the address that Discourse will use. I just added an Exchange Online seat at £2.50/pcm. Then set up a user for that email address.

I setup forum.mydomain.tld as a subdomain in O365 and then added the recommended DNS records at my domain registrar to hook it up to Microsoft’s records and point it at my Digital Ocean droplet.

Next set up a connector (O365 Admin page -> Admin -> Exchange -> Mail Flow -> Connectors). Create a new connector from ‘Your organisation’s email server’ to ‘Office 365’, then on the next panel tell O365 to identify email from an IP address - enter the IP address of your Discourse install. Hit save to create the connector.

Finally go to your domain management page and look at the DNS details for the domain you will be sending email from (for me it is mydomain.tld). Copy the address of the MX server - probably something like mydomain-tld.mail.protection.outlook.com

Then log in to the host of your docker, and edit your app.yml file to include the following:

DISCOURSE_SMTP_ADDRESS: [MX server address]
DISCOURSE_SMTP_PORT: 25
DISCOURSE_SMTP_USER_NAME: blank
DISCOURSE_SMTP_PASSWORD: blank
DISCOURSE_SMTP_AUTHENTICATION: none
DISCOURSE_SMTP_ENABLE_START_TLS: false

Rebuild your app and it should all work.

Matt

2 Likes

We have an Enterprise O365 plan which is limited to 10,000 recipients a day - hence why we use SendGrid for our bulk email requirements.

Here’s a screen grab showing Exchange Online sender limits, note the SMTP throttle.

As @codinghorror mentioned, even if you fit within the above limits, bulk email is against O365 and Exchange Online’s T&Cs and if they suspect abuse, they will blacklist your I.P. or suspend your account depending on your DHCP status.

1 Like

Ooh. Thanks for the info.

At the minute we’re just getting started (pretty much at a building/debugging stage) but I’ll move to a more appropriate service once we’re properly public and up to speed - just needed something to send on activation emails without costing a fortune.

1 Like

Thanks Matt - worked perfectly!

1 Like