邮件与 smtp.office365.com

我正在按照 Troubleshoot email on a new Discourse install - #2 中的步骤排查新部署的 Discourse 实例为何无法发送邮件。

我可以从该设备上使用 swaks 发送邮件。

在设置完全限定域名后,我可以 telnet 连接到邮件服务器 smtp.office365.com 的 587 端口。

生产日志中似乎没有报错。

tail -f shared/web_only/log/rails/production.log
Started POST "/u/action/send_activation_email" for 115.64.14.90 at 2019-12-23 08:20:28 +0000
Processing by UsersController#send_activation_email as */*
  Parameters: {"username"=>"csmu"}
  Rendering text template
  Rendered text template (Duration: 0.1ms | Allocations: 1)
Completed 200 OK in 36ms (Views: 1.0ms | ActiveRecord: 0.0ms | Allocations: 4557)

我注意到类似这样的信息:

Cannot open main log file "/var/log/exim4/mainlog"

当我运行 tail -f shared/web_only/log/var-log/mail.log 时会出现。

有人知道为什么 “/var/log/exim4/mainlog” 会被锁定,并且会在 shared/web_only/log/var-log/mail.log 中被引用吗?

该日志是误报。

主要问题在于与 smtp.office365.com 通信。

  1. 必须将设备设置为使用有效的完全限定域名。在此之前,执行 telnet smtp.office365.com 587 会失败。
  2. 必须在 YAML 文件中设置正确的配置,特别是 DISCOURSE_SMTP_AUTHENTICATION: login
  DISCOURSE_SMTP_ADDRESS: smtp.office365.com
  DISCOURSE_SMTP_PORT: 587
  DISCOURSE_SMTP_USER_NAME: discourse@domain
  DISCOURSE_SMTP_PASSWORD: "validPassword"
  DISCOURSE_SMTP_AUTHENTICATION: login
  DISCOURSE_SMTP_ENABLE_START_TLS: true
  1. 必须设置 SiteSetting.notification_email:
./launcher enter web_only
root@discourse-web-only:/var/www/discourse# rails console
[1] pry(main)> SiteSetting.notification_email = "discourse@domain"
[2] pry(main)> exit
root@discourse-web-only:/var/www/discourse# exit
  1. 重启容器:
./launcher destroy web_only
./launcher start web_only
  1. 任务完成!