Google G Suite Relay SMTP 不工作

你好,我第一次尝试在 DigitalOcean 的 Linux VPS 上安装 Discourse。该 VPS 上通过 Nginx 托管了多个站点,我按照这篇教程在单台机器上安装 Discourse 并配置多个站点:Run other websites on the same machine as Discourse - #182 by angus

Discourse 已成功安装并正常运行。但当我创建管理员账户时,从未收到邮件。我参考了这篇教程:crunchify[dot]com/how-to-setup-email-for-discourse-forum-with-google-apps-smtp-relay-right-way/

我的服务器使用 Postfix 将邮件中继到 Google G Suite,并且与 WordPress 和 MyBB 配合工作正常。不过,上述教程并未提及 Postfix,我推测它是直接连接到 Google G Suite 的。

我还参考了这篇关于排查新安装 Discourse 邮件问题的指南:meta.discourse[dot]org/t/troubleshooting-email-on-a-new-discourse-install/16326

我可以成功 telnet 到 SMTP 中继服务器:

$ sudo telnet smtp-relay.gmail.com 587
Trying 2607:f8b0:400d:c04::1c...
Connected to smtp-relay.gmail.com.
Escape character is '^]'.
220 smtp-relay.gmail.com ESMTP n18sm708840ooi.26 - gsmtp

生产日志显示如下:

Rendering layouts/email_template.html.erb
  Rendered layouts/email_template.html.erb (Duration: 0.1ms | Allocations: 32)
Delivered mail cf23dab4-3e43-421e-8e54-228489c58874@forums.neuronootropic.org (610.1ms)
Job exception: end of file reached

  Rendering layouts/email_template.html.erb
  Rendered layouts/email_template.html.erb (Duration: 0.2ms | Allocations: 32)
Delivered mail a092f703-b590-4792-bd73-d9e4700c3e3c@forums.neuronootropic.org (261.1ms)
Job exception: end of file reached

我尝试在 app.yml 配置文件中将发件人邮箱设置为 noreply@forums.neuronootropic.org,因为我确认该邮箱可用,但结果依旧。邮件仍然以那些带数字的地址发送,我猜测这是某种加密?但这些邮件从未到达我的收件箱。


我的另一个问题是 Nginx。昨天一切正常,但今天我在 app.yml 配置文件中将 URL 从子域名改为了子目录,想测试一下是否子域名导致了邮件问题,因为我的当前论坛 MyBB 运行在子目录下且邮件功能正常。

这一操作似乎破坏了 Nginx。不知何故,Nginx 现在试图从 Discourse 目录加载 SSL 证书,尽管我的 Nginx 配置文件中并未指定该证书。错误信息如下:

$ sudo nginx -t
nginx: [emerg] BIO_new_file("/var/discourse/shared/standalone/ssl/ssl.crt") failed (SSL: error:02001002:system library:fopen:No such file or directory:fopen('/var/discourse/shared/standalone/ssl/ssl.crt','r') error:2006D080:BIO routines:BIO_new_file:no such file)
nginx: configuration file /etc/nginx/nginx.conf test failed

我使用的是 Let’s Encrypt 的 SSL 证书,目前运行正常。在我尝试将 Discourse 部署到子目录而非子域名之前,Nginx 昨天没有任何问题。

如有任何帮助,不胜感激。

我实际上尚未配置 G-Suite 中继用于邮件发送,但看起来您需要在 G-Suite 管理员账户中将 forum.neuronootropic.org 添加并验证为发件域名。如果是这种情况,根据 Google 的文档,没有理由无法正常工作。

不过,如果您已在 G-Suite 中验证了 neuronootr0pic.org,则可以使用类似 noreply_forum@neuronootropic.org 的地址来发送邮件。

感谢建议。

我回去测试了邮箱,发现它只能接收邮件,无法从 noreply@forums.neuronootropic.org 地址发送邮件。我在 G Suite 中将其设置为独立域名,原以为主域名的 MX 记录就足以同时支持两者。

事实并非如此。我为 forums.neuronootropic.org 添加了 MX 记录,现在可以正常收发邮件了。

不过,Discourse 在管理员注册时仍然没有发送激活邮件。

有什么建议吗?

另外,我不确定为什么 Nginx 在尝试从 Discourse 目录加载 SSL 证书,而我从未指定过这一配置。对于这个问题,有什么解决思路吗?

编辑:我将通知邮箱设置更改为从主域名发送邮件,而不是子域名。重新构建了 Discourse,但它仍然从子域名发送邮件。

exec: rails r "SiteSetting.notification_email='noreply@neuronootropic.org'"

$ tail shared/standalone/log/rails/production.log
  Parameters: {"authenticity_token"=>"K6dxoAPvh8PEU6mLHjyFRhY/CcZFFIalhrX08AIh9EgGuOHrJos7i1w0dgdS7okeoSBTrmWJSsc77YpfTnMO4A=="}
  Rendering finish_installation/resend_email.html.erb within layouts/finish_installation
  Rendered finish_installation/resend_email.html.erb within layouts/finish_installation (Duration: 0.4ms | Allocations: 110)
  Rendered layouts/_head.html.erb (Duration: 0.4ms | Allocations: 145)
Completed 200 OK in 19ms (Views: 7.8ms | ActiveRecord: 0.0ms | Allocations: 3036)
  Rendering layouts/email_template.html.erb
  Rendered layouts/email_template.html.erb (Duration: 0.1ms | Allocations: 32)
Delivered mail bce41ef8-2288-42cd-b7ae-e1eb990a4646@forums.neuronootropic.org (705.1ms)
Job exception: end of file reached

我已修复了 nginx 问题。原来 sites-enabled 目录中存在一个 nginx 配置文件的保存副本。我不确定它是如何出现在那里的,因为我是将 sites-available 中的文件链接到 sites-enabled,并且从不直接操作 sites-enabled 目录。

G Suite Relay SMTP 的问题仍然存在。我不明白原因。Discourse 的生产日志中未提及任何错误。

Discourse 诊断工具输出:

==================== 邮件测试 ====================
若要进行全面测试,请访问 http://www.mail-tester.com/ 获取一个测试邮箱地址。
或者,只需向您自己发送一封测试邮件。
请输入用于邮件测试的邮箱地址(输入 'n' 以跳过)[forums@neuronootropic.org]: forums@neuronootropic.org
正在向 forums@neuronootropic.org 发送邮件...
正在测试通过 smtp-relay.gmail.com:587 向 forums@neuronootropic.org 发送邮件。
======================================== 错误 ========================================
                                    意外错误

已到达文件末尾

====================================== 解决方案 =======================================
这不是一个常见错误,目前没有推荐的解决方案!

请将上述确切的错误信息报告至 https://meta.discourse.org/
(如果您找到了解决方案,也请一并告知!)
=======================================================================================

这表示什么意思?

我……呃,在 G Suite 中设置中继时忘了点保存,哈哈

现在邮件可以正常使用了。:slightly_smiling_face: