# SMTP with office365?

**URL:** <https://meta.discourse.org/t/smtp-with-office365/77467>\
**Category:** Self-hosting\
**Tags:** email\
**Created:** [January 8, 2018, 11:57am UTC](https://meta.discourse.org/t/smtp-with-office365/77467 "2018-01-08T11:57:45Z")\
**Posts on this page:** 14\
**Page:** 1

## AI-generated summary

Users discuss configuring SMTP with Office365 for Discourse. [Chopper](/t/-/77467/1) initially faced issues due to mismatched notification and SMTP usernames, which was resolved. [SvenC56](/t/-/77467/5) experienced inconsistent email delivery, with some users not receiving emails, possibly due to Office365's spam filtering or VERP. [pfaffman](/t/-/77467/4) and [itsbhanusharma](/t/-/77467/9) suggest ensuring the notification email matches the SMTP user and checking for VERP. [TheLaserGuy](/t/-/77467/11) provides detailed steps for setting up Office365 for direct delivery, including domain verification, license assignment, and enabling authenticated SMTP. [RPGpro](/t/-/77467/12) notes that disabling security defaults was key for SMTP authentication. [LeeNeighoff](/t/-/77467/13) confirms that SMTP can work with MFA enforcement by using an app password and adjusting timeouts.

<div class="post-metadata">

**Author:** ![Chopper](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/chopper/32/57073_2.png) [@Chopper](https://meta.discourse.org/u/Chopper)\
**Post date:** [January 8, 2018, 11:57am UTC](https://meta.discourse.org/t/smtp-with-office365/77467/1 "2018-01-08T11:57:45Z")

</div>

Hello

I try to use Office365 as SMTP for discourse. I’m already using this account for my wordpress SMTP so the account is not the problem.

When i try to send a email test, an error message appear

> [Sender] 504 5.7.4 Unrecognized authentication type [[AM3PR05CA0123.eurprd05.prod.outlook.com](http://AM3PR05CA0123.eurprd05.prod.outlook.com)]

This is my SMTP config from app.yml

```
## TODO: The SMTP mail server used to validate new accounts and send notifications
DISCOURSE_SMTP_ADDRESS: smtp.office365.com
DISCOURSE_SMTP_PORT: 587
DISCOURSE_SMTP_USER_NAME: test@example.fr
DISCOURSE_SMTP_PASSWORD: password
DISCOURSE_SMTP_AUTHENTICATION: login
DISCOURSE_SMTP_ENABLE_START_TLS: false 

```

Any idea how to fix the problem ?

Another config:

```
## TODO: The SMTP mail server used to validate new accounts and send notifications
DISCOURSE_SMTP_ADDRESS: smtp.office365.com
DISCOURSE_SMTP_PORT: 587
DISCOURSE_SMTP_USER_NAME: test@example.fr
DISCOURSE_SMTP_PASSWORD: password
DISCOURSE_SMTP_AUTHENTICATION: login
DISCOURSE_SMTP_ENABLE_START_TLS: true

```

I get the following error:

> 550 5.7.60 SMTP; Client does not have permissions to send as this sender

**The problem is from Discourse** , because I can test with swaks and it’s working

```
swaks --to test@example.com --from test2@example.com --server smtp.office365.com --auth login --auth-user test2@example.com -tls

```

---

<div class="post-metadata">

**Author:** ![itsbhanusharma](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/itsbhanusharma/32/180717_2.png) [@itsbhanusharma](https://meta.discourse.org/u/itsbhanusharma)\
**Post date:** [January 8, 2018, 1:45pm UTC](https://meta.discourse.org/t/smtp-with-office365/77467/2 "2018-01-08T13:45:35Z")

</div>

> [@Chopper](#):
>
> DISCOURSE\_SMTP\_AUTHENTICATION: login  
> DISCOURSE\_SMTP\_ENABLE\_START\_TLS: false

Not Suggesting that You use office365 for SMTP but it seems like DISCOURSE\_SMTP\_AUTHENTICATION: login isn’t required … maybe try commenting that out and try again with STARTTLS set to True?

---

<div class="post-metadata">

**Author:** ![Chopper](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/chopper/32/57073_2.png) [@Chopper](https://meta.discourse.org/u/Chopper)\
**Post date:** [January 8, 2018, 1:56pm UTC](https://meta.discourse.org/t/smtp-with-office365/77467/3 "2018-01-08T13:56:20Z")

</div>

Okay the problem is now fixed. Huge mistake from my side : the email from Admin → settings → notification email was not the same from the smtp username.  
Maybe a check should be made to prevent user to makes this mistake 🤨

> but it seems like DISCOURSE\_SMTP\_AUTHENTICATION: login isn’t required

True, the final config

```
DISCOURSE_SMTP_ADDRESS: smtp.office365.com
DISCOURSE_SMTP_PORT: 587
DISCOURSE_SMTP_USER_NAME: test@example.fr
DISCOURSE_SMTP_PASSWORD: password
DISCOURSE_SMTP_AUTHENTICATION: login
DISCOURSE_SMTP_ENABLE_START_TLS: true

```

---

<div class="post-metadata">

**Author:** ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)\
**Post date:** [January 8, 2018, 2:48pm UTC](https://meta.discourse.org/t/smtp-with-office365/77467/4 "2018-01-08T14:48:35Z")

</div>

> [@Chopper](#):
>
> Maybe a check should be made to prevent user to makes this mistake

Discourse cannot guess what addresses the mail server will deliver for.

---

<div class="post-metadata">

**Author:** ![SvenC56](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/svenc56/32/132235_2.png) [@SvenC56](https://meta.discourse.org/u/SvenC56)\
**Post date:** [February 24, 2019, 12:26pm UTC](https://meta.discourse.org/t/smtp-with-office365/77467/5 "2019-02-24T12:26:16Z")

</div>

> [@Chopper](#):
>
> True, the final config
> 
> ```plaintext
> DISCOURSE_SMTP_ADDRESS: smtp.office365.com
> DISCOURSE_SMTP_PORT: 587
> DISCOURSE_SMTP_USER_NAME: test@example.fr
> DISCOURSE_SMTP_PASSWORD: password
> DISCOURSE_SMTP_AUTHENTICATION: login
> DISCOURSE_SMTP_ENABLE_START_TLS: true
> 
> ```

Sadly this solution is not working for me (I also tried to escape the password). I tried it with this [SMTP setting problem with Office365 - #5 by ianwhite](https://meta.discourse.org/t/smtp-setting-problem-with-office365/61630/5) one which is working. But not everybody gets E-Mails… 🤔

---

<div class="post-metadata">

**Author:** ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)\
**Post date:** [February 24, 2019, 3:00pm UTC](https://meta.discourse.org/t/smtp-with-office365/77467/6 "2019-02-24T15:00:31Z")

</div>

If _some_ people get mail then it’s the fault of office365, or their mail provider. The others should check their spam folder, though if they use a service life office365 it will silently drop mail that it thinks is spam.

---

<div class="post-metadata">

**Author:** ![SvenC56](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/svenc56/32/132235_2.png) [@SvenC56](https://meta.discourse.org/u/SvenC56)\
**Post date:** [February 24, 2019, 3:26pm UTC](https://meta.discourse.org/t/smtp-with-office365/77467/7 "2019-02-24T15:26:42Z")

</div>

> [@Chopper](#):
>
> True, the final config
> 
> ```plaintext
> DISCOURSE_SMTP_ADDRESS: smtp.office365.com
> DISCOURSE_SMTP_PORT: 587
> DISCOURSE_SMTP_USER_NAME: test@example.fr
> DISCOURSE_SMTP_PASSWORD: password
> DISCOURSE_SMTP_AUTHENTICATION: login
> DISCOURSE_SMTP_ENABLE_START_TLS: true
> 
> ```

I tried it with these settings. In the skipped section in the email tab I can see the following error:

554 5.2.0 STOREDRV.Submission.Exception:SendAsDeniedException.MapiExceptionSendAsDenied;

---

<div class="post-metadata">

**Author:** ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)\
**Post date:** [February 24, 2019, 4:52pm UTC](https://meta.discourse.org/t/smtp-with-office365/77467/8 "2019-02-24T16:52:08Z")

</div>

Sounds like the address you are sending from is not one that the mail server supports. There is a line at the bottom of app.yml that week let you set the notification address. (you can set it in sure settings if you’re logged in)

---

<div class="post-metadata">

**Author:** ![itsbhanusharma](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/itsbhanusharma/32/180717_2.png) [@itsbhanusharma](https://meta.discourse.org/u/itsbhanusharma)\
**Post date:** [February 24, 2019, 4:55pm UTC](https://meta.discourse.org/t/smtp-with-office365/77467/9 "2019-02-24T16:55:53Z")

</div>

Or maybe they have VERP enabled so the email address is `replies+{key}@example.com` instead of the authorized `noreply@example.com` That was the issue I’ve faced in past while trying to send mails from my own mail server. It’s usually easy to fix though.

---

<div class="post-metadata">

**Author:** ![rjcabs](https://avatars.discourse-cdn.com/v4/letter/r/e9a140/32.png) [@rjcabs](https://meta.discourse.org/u/rjcabs)\
**Post date:** [August 5, 2021, 8:40pm UTC](https://meta.discourse.org/t/smtp-with-office365/77467/10 "2021-08-05T20:40:30Z")

</div>

Yes. This worked for me. Two things in the initial setup:

```plaintext
DISCOURSE_SMTP_USER_NAME:
-- AND --
DISCOURSE_NOTIFICATION_EMAIL:

```

needed to be set to the same email.

---

<div class="post-metadata">

**Author:** ![TheLaserGuy](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/thelaserguy/32/303666_2.png) [@TheLaserGuy](https://meta.discourse.org/u/TheLaserGuy)\
**Post date:** [April 21, 2023, 4:12pm UTC](https://meta.discourse.org/t/smtp-with-office365/77467/11 "2023-04-21T16:12:20Z")

</div>

Some up to date instructions for anyone struggling with office365 & direct-delivery

- Go to Microsoft admin center
- Click on Settings then Domains
- Click on Add Domain
- Follow the instructions on the screen to add your forum’s URL (example: forum:yourlinks.com)
- Once you’ve completed the above steps and the DNS is verified, you’re now able to create an inbox using that subdomain
- Click on Users and then Active users
- Click on Add a user
- Create the mailbox for your forum (example: [noreply@forum.yourlinks.com](mailto:noreply@forum.yourlinks.com)) mailbox domain must match the hostname from where the forum runs
- Click on Licenses & Apps
- Assign this mailbox an Exchange Online (Plan 1) license (10,000 messages daily 30msg/min throttle) It is required to have a license attached to the mailbox for the purpose of direct-delivery. At the time of writing, the cost is $4.00USD/mo or $5.10/CAD | Should you require a higher limit or a shorter throttle, there are other plans available
- Click on Mail and then Manage email apps
- Enable “Authenticated SMTP”
- Click Save changes
- Go to your Azure portal
- Browse to your active directory
- Select Properties in the left sidebar, right under User settings
- Select Manage security defaults
- Set Security defaults to “disabled”
- Click save
- Go back to Users \> Active users
- Click on Multi-factor authentication
- Disable MFA on the mailbox being used

The mailbox is now ready for use by your Discourse.

---

<div class="post-metadata">

**Author:** ![RPGpro](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/rpgpro/32/317918_2.png) [@RPGpro](https://meta.discourse.org/u/RPGpro)\
**Post date:** [August 17, 2023, 1:00pm UTC](https://meta.discourse.org/t/smtp-with-office365/77467/12 "2023-08-17T13:00:03Z")

</div>

> Set Security defaults to “disabled”

This was the one thing that was stopping SMTP auth…  
Been banging my head against a wall for days…  
Why do MS make things so difficult…?

---

<div class="post-metadata">

**Author:** ![LeeNeighoff](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/leeneighoff/32/282406_2.png) [@LeeNeighoff](https://meta.discourse.org/u/LeeNeighoff)\
**Post date:** [September 9, 2023, 5:01pm UTC](https://meta.discourse.org/t/smtp-with-office365/77467/13 "2023-09-09T17:01:28Z")

</div>

Disabling security defaults may no longer be necessary with MFA enforcement. If you enable and then enforce MFA on a M365 account, you can go to the account’s MFA setup page and add an app password to use and bypass MFA. I got it working with a M365 Business Basic-licensed user with MFA enforcement, SMTP AUTH, and security defaults all enabled. I just had to turn up the SMTP open and read timeouts with two additional lines. 30 may be excessive, but 5 was too little.

Working app.yml entry, as of September 2023:

```plaintext
  DISCOURSE_SMTP_ADDRESS: smtp.office365.com
  DISCOURSE_SMTP_PORT: 587
  DISCOURSE_SMTP_USER_NAME: user@domain.com
  DISCOURSE_SMTP_PASSWORD: whatever-your-app-password-is
  DISCOURSE_SMTP_AUTHENTICATION: login
  DISCOURSE_SMTP_ENABLE_START_TLS: true
  DISCOURSE_NOTIFICATION_EMAIL: user@domain.com
  DISCOURSE_SMTP_OPEN_TIMEOUT: 30
  DISCOURSE_SMTP_READ_TIMEOUT: 30

```

---

<div class="post-metadata">

**Author:** ![JammyDodger](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jammydodger/32/254611_2.png) [@JammyDodger](https://meta.discourse.org/u/JammyDodger)\
**Post date:** [June 8, 2024, 12:36pm UTC](https://meta.discourse.org/t/smtp-with-office365/77467/14 "2024-06-08T12:36:42Z")

</div>

Closed on June 8, 2024, 12:36pm UTC

This topic was automatically closed after 2343 days. New replies are no longer allowed.
