使用 Office365 的 SMTP 吗?

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 个赞

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

4 个赞

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 个赞

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 个赞

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 个赞

一些最新的说明,供仍在为 office365 和直接发送而苦苦挣扎的人们参考

  • 前往 Microsoft 管理中心
  • 点击“设置”,然后点击“域”
  • 点击“添加域”
  • 按照屏幕上的说明添加论坛的 URL(例如:forum:yourlinks.com)
  • 完成以上步骤并验证 DNS 后,您现在就可以使用该子域创建收件箱了
  • 点击“用户”,然后点击“活动用户”
  • 点击“添加用户”
  • 为您的论坛创建邮箱(例如:noreply@forum.yourlinks.com),邮箱域必须与论坛运行的主机名匹配
  • 点击“许可证和应用”
  • 为此邮箱分配 Exchange Online (Plan 1) 许可证(每天 10,000 条消息,30 条消息/分钟限制)。邮箱必须附加许可证才能进行直接发送。撰写本文时,成本为 4.00 美元/月 或 5.10 加元/月 | 如果您需要更高的限制或更短的节流时间,还有其他计划可供选择
  • 点击“邮件”,然后点击“管理邮件应用”
  • 启用“已验证的 SMTP”
  • 点击“保存更改”
  • 前往您的 Azure 门户
  • 浏览到您的活动目录
  • 在左侧边栏中,在“用户设置”正下方选择“属性”
  • 选择“管理安全默认设置”
  • 将“安全默认设置”设置为“已禁用”
  • 点击“保存”
  • 返回“用户”>“活动用户”
  • 点击“多重身份验证”
  • 禁用正在使用的邮箱上的 MFA

现在该邮箱已准备好供您的 Discourse 使用。

1 个赞

“禁用”安全默认设置

这是阻止 SMTP 身份验证的唯一因素……
我为此苦恼了好几天……
为什么微软要让事情变得如此困难……?

禁用安全默认设置可能不再是强制执行 MFA 的必要条件。如果您为 M365 帐户启用然后强制执行 MFA,您可以转到该帐户的 MFA 设置页面并添加一个应用程序密码以绕过 MFA。我通过启用 MFA 强制执行、SMTP AUTH 和安全默认设置的 M365 Business Basic 许可用户成功实现了这一点。我只需要通过另外两行来提高 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
1 个赞

此主题已在 2343 天后自动关闭。不再允许回复。