# SMTP unrecognized authentication type with Office 365

**URL:** https://meta.discourse.org/t/smtp-unrecognized-authentication-type-with-office-365/145830
**Category:** Self-hosting
**Tags:** email
**Created:** [March 27, 2020, 3:34pm UTC](https://meta.discourse.org/t/smtp-unrecognized-authentication-type-with-office-365/145830 "2020-03-27T15:34:14Z")
**Posts on this page:** 15
**Page:** 1

<div class="post-metadata">

### Author: ![schap](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/schap/32/148773_2.png) [@schap](https://meta.discourse.org/u/schap)
#### Post date: [March 27, 2020, 3:34pm UTC](https://meta.discourse.org/t/smtp-unrecognized-authentication-type-with-office-365/145830/1 "2020-03-27T15:34:14Z")

</div>

I am getting this error and have tried so many different options. Using Office 365

```
Error: 504 5.7.4 Unrecognized authentication type [MN2PR20CA0010.namprd20.prod.outlook.com]

Settings here:

  DISCOURSE_SMTP_ADDRESS: smtp.office365.com
  DISCOURSE_SMTP_PORT: 587
  DISCOURSE_SMTP_USER_NAME: email
  DISCOURSE_SMTP_PASSWORD: "PASSWORD"
  DISCOURSE_SMTP_ENABLE_START_TLS: true

```

---

<div class="post-metadata">

### Author: ![evantill](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/evantill/32/116219_2.png) [@evantill](https://meta.discourse.org/u/evantill)
#### Post date: [March 29, 2020, 11:50am UTC](https://meta.discourse.org/t/smtp-unrecognized-authentication-type-with-office-365/145830/2 "2020-03-29T11:50:40Z")

</div>

try your configuration using openssl tool first

1. Encode your office365 user

```shell
echo -n "your email here " | openssl enc -base64
xxx_encoded_email_xxx

```

2.Encode your password

```shell
echo -n "your password here" | openssl enc -base64
xxx_encoded_password_xxx

```

3.Open a connection

```shell
openssl s_client -connect SMTP.office365.com:587 -starttls smtp -quiet -crlf

```

4.Test authentification

- wait for the message `250 SMTPUTF8`
- send `EHLO SMTP.office365.com`
- wait for response

```plaintext
250-PR3P189CA0029.outlook.office365.com Hello [88.138.0.68]
250-SIZE 157286400
250-PIPELINING
250-DSN
250-ENHANCEDSTATUSCODES
250-AUTH LOGIN XOAUTH2
250-8BITMIME
250-BINARYMIME
250-CHUNKING
250 SMTPUTF8

```

- send `AUTH LOGIN`
- wait for `334 VXNlcm5hbWU6`
- send your encoded user login `xxx_encoded_email_xxx`
- wait for `334 UGFzc3dvcmQ6`
- send your encoded password `xxx_encoded_password_xxx`
- wait for response `235 2.7.0 Authentication successful`

---

<div class="post-metadata">

### Author: ![JMadd](https://avatars.discourse-cdn.com/v4/letter/j/7ab992/32.png) [@JMadd](https://meta.discourse.org/u/JMadd)
#### Post date: [April 24, 2020, 4:48pm UTC](https://meta.discourse.org/t/smtp-unrecognized-authentication-type-with-office-365/145830/3 "2020-04-24T16:48:49Z")

</div>

So if the openssl test works but the connection test run by discourse-doctor still fails when using those settings what is next? Even though the openssl test works my discourse connection still fails with 504 5.7.4 Unrecognized authentication type… Presumably it is not recognizing the LOGIN auth method. I tried adding DISCOURSE\_SMTP\_AUTHENTICATION: login to the app.yml file, but that has not helped.

---

<div class="post-metadata">

### Author: ![JMadd](https://avatars.discourse-cdn.com/v4/letter/j/7ab992/32.png) [@JMadd](https://meta.discourse.org/u/JMadd)
#### Post date: [April 27, 2020, 1:22am UTC](https://meta.discourse.org/t/smtp-unrecognized-authentication-type-with-office-365/145830/4 "2020-04-27T01:22:40Z")

</div>

FWIW, here is what I have found. I went into the docker image and started monkeying around with the lib/tasks/emails.rake script and the config/discourse.conf file. Several hours later, after trying every possible combination of [smtp.office365.com](http://smtp.office365.com) and .mail.protection.outlook.com AUTH login and AUTH plain I uncommented the block above the STMP start.

```
# We would like to do this, but Net::SMTP errors out using starttls
#Net::SMTP.start(smtp[:address], smtp[:port]) do |s|
# s.starttls if !!smtp[:enable_starttls_auto] && s.capable_starttls?
# s.auth_login(smtp[:user_name], smtp[:password])
#end

```

Running that as-is resulted in a read timeout.  
Modifying it like this - calling new rather than start resulted in a successful send.

```
Net::STMP.new(smtp[:address], smtp[:port]) do |s|
    s.enable_starttls
    s.auth_login(smtp[:user_name], smtp[:password])
end

```

This is my first exposure to Ruby, rake and friends. I can’t explain why it works or if is a ‘good thing’ for general cases.  
J.

---

<div class="post-metadata">

### Author: ![JMadd](https://avatars.discourse-cdn.com/v4/letter/j/7ab992/32.png) [@JMadd](https://meta.discourse.org/u/JMadd)
#### Post date: [April 27, 2020, 1:33am UTC](https://meta.discourse.org/t/smtp-unrecognized-authentication-type-with-office-365/145830/5 "2020-04-27T01:33:44Z")

</div>

Oh, also I never was able to get it to work to the my\_domain.mail.protection.outlook.com on either 25 or 587, what worked was `smtp.office365.com:587`.

---

<div class="post-metadata">

### Author: ![thfisher](https://avatars.discourse-cdn.com/v4/letter/t/c67d28/32.png) [@thfisher](https://meta.discourse.org/u/thfisher)
#### Post date: [July 25, 2020, 1:16pm UTC](https://meta.discourse.org/t/smtp-unrecognized-authentication-type-with-office-365/145830/6 "2020-07-25T13:16:38Z")

</div>

I use [socketlabs.com](http://socketlabs.com) as my email delivery service, and had a similar issue. In my case the solution was to edit lib/tasks/emails.rake as follows:  
Change the line:  
`Net::SMTP.start(smtp[:address], smtp[:port], 'localhost', smtp[:user_name], smtp[:password])`  
to  
`Net::SMTP.start(smtp[:address], smtp[:port], 'localhost', smtp[:user_name], smtp[:password], smtp[:authentication])`

Without this change, the DISCOURSE\_SMTP\_AUTHENTICATION: login doesn’t get passed to the lower level SMTP code.

I haven’t tested this to see if the modified code still works for other authentication methods, but it fixes the problem for login authentication.

---

<div class="post-metadata">

### Author: ![gzegzol](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/gzegzol/32/191892_2.png) [@gzegzol](https://meta.discourse.org/u/gzegzol)
#### Post date: [August 27, 2020, 11:15am UTC](https://meta.discourse.org/t/smtp-unrecognized-authentication-type-with-office-365/145830/7 "2020-08-27T11:15:10Z")

</div>

I can confirm, that adding  
`smtp[:authentication]`  
to `Net::SMTP.start` call and setting  
`DISCOURSE_SMTP_AUTHENTICATION: login`  
in `app.yml` fixes the issue for email test page.

I believe, that regular emails are send via `mail` library, and setting  
`DISCOURSE_SMTP_AUTHENTICATION: login`  
in `app.yml` is enough for the library to work correctly.

Still, I believe, that `lib/tasks/emails.rake` should be patched to use `DISCOURSE_SMTP_AUTHENTICATION` setting. This would save some unnecessary debugging .

---

<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: [September 1, 2020, 2:43pm UTC](https://meta.discourse.org/t/smtp-unrecognized-authentication-type-with-office-365/145830/8 "2020-09-01T14:43:00Z")

</div>

Looks like a 🐛 to me. I submitted a PR:

[https://github.com/discourse/discourse/pull/10572](https://github.com/discourse/discourse/pull/10572)

---

<div class="post-metadata">

### Author: ![stuartiannaylor](https://avatars.discourse-cdn.com/v4/letter/s/f475e1/32.png) [@stuartiannaylor](https://meta.discourse.org/u/stuartiannaylor)
#### Post date: [September 17, 2020, 9:20pm UTC](https://meta.discourse.org/t/smtp-unrecognized-authentication-type-with-office-365/145830/9 "2020-09-17T21:20:15Z")

</div>

Hi,

Net::SMTP.start(smtp[:address], smtp[:port], ‘localhost’, smtp[:user\_name], smtp[:password], smtp[:authentication])  
rescue Exception =\> e

Has been patched as above in my current version but still get the same.

Error: 504 5.7.4 Unrecognized authentication type with [smtp.office365.com](http://smtp.office365.com).

Anyone have any ideas?

---

<div class="post-metadata">

### Author: ![tahoetech](https://avatars.discourse-cdn.com/v4/letter/t/ccd318/32.png) [@tahoetech](https://meta.discourse.org/u/tahoetech)
#### Post date: [November 16, 2020, 5:24am UTC](https://meta.discourse.org/t/smtp-unrecognized-authentication-type-with-office-365/145830/10 "2020-11-16T05:24:58Z")

</div>

How do I edit the lib/tasks/emails.rake script to get this to work?

---

<div class="post-metadata">

### Author: ![bigfudge](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@bigfudge](https://meta.discourse.org/u/bigfudge)
#### Post date: [April 21, 2021, 12:20pm UTC](https://meta.discourse.org/t/smtp-unrecognized-authentication-type-with-office-365/145830/11 "2021-04-21T12:20:20Z")

</div>

As a general update on this issue, MS are in the process of removing legacy authentication for SMTP and POP3 which is going to make things difficult if you are using O365 as a mail provider. The default policy applied now is to prohibit SMTP AUTH and you need to enable this per-mailbox. Hope that’s useful — I spent yesterday morning banging my head against this wall.

It’s a real shame about POP in particular, because setting up inbound mail is going to get a lot harder unless Discourse adds IMAP support for inbound mailboxes.

---

<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: [April 21, 2021, 12:55pm UTC](https://meta.discourse.org/t/smtp-unrecognized-authentication-type-with-office-365/145830/12 "2021-04-21T12:55:51Z")

</div>

There’s an easy solution for incoming mail that includes a container to receive it. It used to be called "straightforward "but someone objected to the name and it was changed and I can’t find it anymore.

There is also [IMAP support for group inboxes](https://meta.discourse.org/t/imap-support-for-group-inboxes/160588). But it mostly supports Gmail only.

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [April 23, 2021, 12:10am UTC](https://meta.discourse.org/t/smtp-unrecognized-authentication-type-with-office-365/145830/13 "2021-04-23T00:10:24Z")

</div>

Well, running your own mail server should be considered a method of last resort in any case. I believe it was “direct delivery”, try searching for that.

---

<div class="post-metadata">

### Author: ![pierreozoux](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pierreozoux/32/296611_2.png) [@pierreozoux](https://meta.discourse.org/u/pierreozoux)
#### Post date: [February 14, 2023, 10:43am UTC](https://meta.discourse.org/t/smtp-unrecognized-authentication-type-with-office-365/145830/14 "2023-02-14T10:43:01Z")

</div>

As of 2023, pop3 auth is not possible anymore in exchange.

> **[POP, IMAP, and SMTP AUTH - Deprecation of Basic authentication in Exchange...](https://learn.microsoft.com/en-us/exchange/clients-and-mobile-in-exchange-online/deprecation-of-basic-authentication-exchange-online#pop-imap-and-smtp-auth)**
>
> Important | Learn about deprecation of Basic authentication in Exchange Online

---

<div class="post-metadata">

### Author: ![Habib\_Malik](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/habib_malik/32/296171_2.png) [@Habib\_Malik](https://meta.discourse.org/u/Habib_Malik)
#### Post date: [March 3, 2023, 11:17am UTC](https://meta.discourse.org/t/smtp-unrecognized-authentication-type-with-office-365/145830/15 "2023-03-03T11:17:06Z")

</div>

If you are using PHPMailer  
Then try by comments/remove the line and try : //$mail-\>isSMTP(true);
