Tipo di autenticazione SMTP non riconosciuto con Office 365

Sto riscontrando questo errore e ho provato numerose soluzioni diverse. Sto utilizzando Office 365.

Errore: 504 5.7.4 Tipo di autenticazione non riconosciuto [MN2PR20CA0010.namprd20.prod.outlook.com]

Impostazioni qui:

  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

try your configuration using openssl tool first

  1. Encode your office365 user
echo -n "your email here " | openssl enc -base64
xxx_encoded_email_xxx

2.Encode your password

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

3.Open a connection

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
    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
3 Mi Piace

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.

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 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.

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.

1 Mi Piace

Utilizzo socketlabs.com come servizio di consegna email e ho riscontrato un problema simile. Nel mio caso, la soluzione è stata modificare lib/tasks/emails.rake come segue:
Modificare la riga:
Net::SMTP.start(smtp[:address], smtp[:port], 'localhost', smtp[:user_name], smtp[:password])
in
Net::SMTP.start(smtp[:address], smtp[:port], 'localhost', smtp[:user_name], smtp[:password], smtp[:authentication])

Senza questa modifica, DISCOURSE_SMTP_AUTHENTICATION: login non viene passato al codice SMTP di livello inferiore.

Non ho testato se il codice modificato funzioni ancora per altri metodi di autenticazione, ma risolve il problema per l’autenticazione login.

3 Mi Piace

Posso confermare che l’aggiunta di
smtp[:authentication]
alla chiamata Net::SMTP.start e l’impostazione di
DISCOURSE_SMTP_AUTHENTICATION: login
in app.yml risolvono il problema nella pagina di test delle email.

Credo che le email regolari vengano inviate tramite la libreria mail, e che impostare
DISCOURSE_SMTP_AUTHENTICATION: login
in app.yml sia sufficiente per far funzionare correttamente la libreria.

Tuttavia, ritengo che lib/tasks/emails.rake dovrebbe essere corretto per utilizzare l’impostazione DISCOURSE_SMTP_AUTHENTICATION. Questo eviterebbe qualche inutile attività di debug.

1 Mi Piace

Sembra un :bug: a me. Ho inviato una PR:

3 Mi Piace

Ciao,

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

È stato applicato l’aggiornamento come mostrato sopra nella mia versione corrente, ma ricevo ancora lo stesso errore.

Errore: 504 5.7.4 Tipo di autenticazione non riconosciuto con smtp.office365.com.

Qualcuno ha qualche idea?

1 Mi Piace

Come posso modificare lo script lib/tasks/emails.rake per far funzionare tutto?

Come aggiornamento generale su questo problema, Microsoft sta procedendo alla rimozione dell’autenticazione legacy per SMTP e POP3, il che renderà le cose più difficili se utilizzi O365 come provider di posta. La policy applicata di default ora è quella di disabilitare SMTP AUTH e devi abilitarla per ogni casella di posta. Spero che sia utile — ho passato ieri mattina a sbattermi la testa contro questo muro.

È un vero peccato, in particolare per POP, perché configurare la posta in arrivo diventerà molto più complicato a meno che Discourse non aggiunga il supporto IMAP per le caselle di posta in arrivo.

1 Mi Piace

Esiste una soluzione semplice per la posta in arrivo che include un contenitore per riceverla. In passato si chiamava “semplice”, ma qualcuno ha fatto obiezione al nome e l’hanno cambiato, e ora non riesco più a trovarlo.

C’è anche il supporto IMAP per le caselle di gruppo. Tuttavia, è principalmente compatibile solo con Gmail.

3 Mi Piace

Beh, in ogni caso, gestire il proprio server di posta dovrebbe essere considerato un’ultima risorsa. Credo si trattasse di “consegna diretta”, prova a cercare quel termine.

2 Mi Piace

A partire dal 2023, l’autenticazione POP3 non è più possibile in Exchange.

1 Mi Piace

Se stai usando PHPMailer
Prova commentando/rimuovendo la riga e prova: //$mail->isSMTP(true);