SMTP with 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

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

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)

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.

네. 저에게는 이렇게 해결되었습니다. 초기 설정에서 두 가지가 필요합니다:

DISCOURSE_SMTP_USER_NAME:
-- 그리고 --
DISCOURSE_NOTIFICATION_EMAIL:

이 두 값은 동일한 이메일로 설정해야 합니다.

Office365 및 Direct Delivery 설정에 어려움을 겪고 있는 분들을 위한 최신 가이드입니다.

  • Microsoft 관리 센터로 이동합니다.
  • 설정(Settings)을 클릭한 후 도메인(Domains)을 선택합니다.
  • 도메인 추가(Add Domain)를 클릭합니다.
  • 화면의 지침에 따라 포럼 URL(예: forum:yourlinks.com)을 추가합니다.
  • 위 단계를 완료하고 DNS가 확인되면 해당 서브도메인을 사용하여 받은편지함을 생성할 수 있습니다.
  • 사용자(Users)를 클릭한 후 활성 사용자(Active users)를 선택합니다.
  • 사용자 추가(Add a user)를 클릭합니다.
  • 포럼용 메일박스(예: noreply@forum.yourlinks.com)를 생성합니다. 메일박스 도메인은 포럼이 실행되는 호스트명과 일치해야 합니다.
  • 라이선스 및 앱(Licenses & Apps)을 클릭합니다.
  • 이 메일박스에 Exchange Online (Plan 1) 라이선스를 할당합니다(일 10,000개 메시지, 분당 30개 메시지 제한). Direct Delivery를 위해 메일박스에 라이선스가 연결되어 있어야 합니다. 작성 시점 기준 비용은 월 4.00달러(USD) 또는 5.10달러(CAD)입니다. 더 높은 제한이나 더 짧은 제한 시간이 필요하면 다른 플랜도 이용 가능합니다.
  • 메일(Mail)을 클릭한 후 이메일 앱 관리(Manage email apps)를 선택합니다.
  • "Authenticated SMTP"를 활성화합니다.
  • 변경 사항 저장(Save changes)을 클릭합니다.
  • Azure 포털로 이동합니다.
  • 활성 디렉터리를 찾아갑니다.
  • 왼쪽 사이드바에서 사용자 설정(User settings) 바로 아래에 있는 속성(Properties)을 선택합니다.
  • 보안 기본값 관리(Manage security defaults)를 선택합니다.
  • 보안 기본값(Security defaults)을 "비활성화(disabled)"로 설정합니다.
  • 저장(save)을 클릭합니다.
  • 사용자(Users) > 활성 사용자(Active users)로 돌아가기
  • 다중 인증(Multi-factor authentication)을 클릭합니다.
  • 사용 중인 메일박스의 MFA를 비활성화합니다.

이제 해당 메일박스는 Discourse에서 사용할 준비가 되었습니다.

보안 기본값을 “비활성화”로 설정

SMTP 인증을 막고 있던 유일한 원인이었네요…
며칠 동안 벽에 머리를 부딪고 있었는데…
MS는 왜 이렇게 일을 어렵게 만드는 걸까요…?

MFA(다중 인증) 강제 적용으로 인해 보안 기본값을 비활성화할 필요가 없을 수 있습니다. M365 계정에서 MFA를 활성화한 후 강제 적용하면, 해당 계정의 MFA 설정 페이지로 이동하여 앱 비밀번호를 추가하고 MFA를 우회할 수 있습니다. M365 Business Basic 라이선스를 가진 사용자, MFA 강제 적용, SMTP AUTH, 보안 기본값이 모두 활성화된 환경에서 작동하는 것을 확인했습니다. 추가로 두 줄만 추가하여 SMTP 열기 및 읽기 타임아웃을 늘려야 했습니다. 30은 과도할 수 있지만, 5는 너무 짧았습니다.

2023년 9월 기준, 정상 작동하는 app.yml 항목:

  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