¿SMTP con Office365?

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]

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

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?

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 :face_with_raised_eyebrow:

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
4 Me gusta

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

4 Me gusta

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 one which is working. But not everybody gets E-Mails… :thinking:

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.

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;

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)

2 Me gusta

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.

2 Me gusta

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

DISCOURSE_SMTP_USER_NAME:
-- AND --
DISCOURSE_NOTIFICATION_EMAIL:

needed to be set to the same email.

1 me gusta

Algunas instrucciones actualizadas para cualquiera que tenga problemas con Office 365 y entrega directa

  • Vaya al Centro de administración de Microsoft
  • Haga clic en Configuración y luego en Dominios
  • Haga clic en Agregar dominio
  • Siga las instrucciones en pantalla para agregar la URL de su foro (ejemplo: foro:susenlaces.com)
  • Una vez que haya completado los pasos anteriores y se haya verificado el DNS, ahora podrá crear una bandeja de entrada usando ese subdominio
  • Haga clic en Usuarios y luego en Usuarios activos
  • Haga clic en Agregar un usuario
  • Cree el buzón de correo para su foro (ejemplo: noreply@foro.susenlaces.com) el dominio del buzón debe coincidir con el nombre de host desde donde se ejecuta el foro
  • Haga clic en Licencias y aplicaciones
  • Asigne a este buzón una licencia de Exchange Online (Plan 1) (límite de 10,000 mensajes diarios, 30 mensajes/min) Es necesario tener una licencia adjunta al buzón para el propósito de entrega directa. En el momento de escribir esto, el costo es de $4.00 USD/mes o $5.10/CAD | Si requiere un límite más alto o un límite más corto, hay otros planes disponibles
  • Haga clic en Correo y luego en Administrar aplicaciones de correo electrónico
  • Habilite “SMTP autenticado”
  • Haga clic en Guardar cambios
  • Vaya a su portal de Azure
  • Vaya a su directorio activo
  • Seleccione Propiedades en la barra lateral izquierda, justo debajo de Configuración de usuario
  • Seleccione Administrar valores de seguridad
  • Establezca los valores de seguridad en “deshabilitado”
  • Haga clic en guardar
  • Vuelva a Usuarios > Usuarios activos
  • Haga clic en Autenticación multifactor
  • Deshabilite la MFA en el buzón que se está utilizando

El buzón ahora está listo para ser utilizado por su Discourse.

1 me gusta

Establecer los valores predeterminados de seguridad en “deshabilitado”

Esto era lo único que impedía la autenticación SMTP…
He estado dándome cabezazos contra la pared durante días…
¿Por qué Microsoft hace las cosas tan difíciles…?

Deshabilitar los valores predeterminados de seguridad puede que ya no sea necesario con la aplicación de MFA. Si habilitas y luego aplicas MFA en una cuenta de M365, puedes ir a la página de configuración de MFA de la cuenta y agregar una contraseña de aplicación para usar y omitir MFA. Logré que funcionara con un usuario con licencia M365 Business Basic con la aplicación de MFA, SMTP AUTH y los valores predeterminados de seguridad habilitados. Solo tuve que aumentar los tiempos de espera de apertura y lectura de SMTP con dos líneas adicionales. 30 puede ser excesivo, pero 5 era muy poco.

Entrada de app.yml de trabajo, a partir de septiembre de 2023:

  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
1 me gusta

Este tema se cerró automáticamente después de 2343 días. Ya no se permiten nuevas respuestas.