SMTP错误:必须先发出STARTTLS命令

I am trying to configure Discourse 2.7.0.beta4 with the Mailersend SMTP service.

After running ./discourse-doctor I got the error below.

SMTP error: Must issue a STARTTLS command first

This is my current app.yml configuration regarding SMTP.

  DISCOURSE_SMTP_ADDRESS: 'smtp.mailersend.net'
  DISCOURSE_SMTP_PORT: 587
  DISCOURSE_SMTP_USER_NAME: username@subdomain.domain.org
  DISCOURSE_SMTP_PASSWORD: mypasswordhere
 #DISCOURSE_SMTP_ENABLE_START_TLS: true           # (optional, default true)
 #DISCOURSE_SMTP_AUTHENTICATION: login
 #DISCOURSE_SMTP_OPENSSL_VERIFY_MODE: none

I’ve already tried to uncomment and set DISCOURSE_SMTP_ENABLE_START_TLS explicitly as true, but the error remains. The same for DISCOURSE_SMTP_AUTHENTICATION: login.

After any change in the YML file I am restarting the system with this:

./launcher destroy app; ./launcher start app

Any tip about what is going on?

Thanks in advance!

I made some changes to discourse-setup recently and also a change to the rake task you’re using (that I think isn’t merged yet).

If you want to give me access to your server I’ll take a look.

2 个赞

As I mentioned via PM, I can’t give access to the server due to security concerns. But thanks very much to @pfaffman for your help and for trying to solve this issue.

Let me add more context to this issue: a previous admin installed Discourse with the Mailgun SMTP service but it stopped to work and I don’t have access to that account.

As I said, I am trying to configure it now with Mailersend. I have read this topic [1] and others about STARTTLS here in the forum, but I am not sure about how to implement the changes needed.

I tried this setting below as well but the errror remains

DISCOURSE_SMTP_OPENSSL_VERIFY_MODE: none

If it is related to some recent update, maybe is it better to consider a downgrade then?

[1] Can't send email with certificate issue - #3 by supermathie

1 个赞

Did you get this working?

No, I have decided to change for another mail service. Now it’s working fine with Mailjet.

1 个赞

我遇到了类似的问题。昨天我花了大约三个小时调试新 Discourse 实例的电子邮件发送,但都没有成功。我正尝试通过 Fastmail 使用 STARTTLS 在端口 587 上发送电子邮件。其他服务使用相同的凭据可以正常工作。

使用这些设置时,我没有收到“必须先发出 STARTTLS 命令”的错误响应:

DISCOURSE_SMTP_ADDRESS: 'smtp.fastmail.com'
DISCOURSE_SMTP_PORT: 587
DISCOURSE_SMTP_USER_NAME: 'myuser@fastmail.fm'
DISCOURSE_SMTP_PASSWORD: 'mypass'
DISCOURSE_SMTP_ENABLE_START_TLS: true

…然后运行 ./launcher rebuild app,当我运行 ./discourse-doctor 并发送电子邮件时,我会收到 500 5.5.1 Invalid command 错误响应。

今天我开始使用 tcpdump 跟踪通信,并注意到 Discourse 似乎并没有真正使用 STARTTLS。以下是我发送 Grafana 恢复电子邮件时发生的情况:

< 220 smtp.fastmail.com ESMTP ready
> EHLO 9b5ba1569f77
< 250-smtp.fastmail.com
< 250-PIPELINING
< 250-SIZE 71000000
< 250-ENHANCEDSTATUSCODES
< 250-8BITMIME
< 250 STARTTLS
> STARTTLS
< ...[encrypted]

但是使用 Discourse 时,会发生这种情况:

< 220 smtp.fastmail.com ESMTP ready
> EHLO localhost
< 250-smtp.fastmail.com
< 250-PIPELINING
< 250-SIZE 71000000
< 250-ENHANCEDSTATUSCODES
< 250-8BITMIME
< 250 STARTTLS
> AUTH PLAIN [redacted]
< 500 5.5.1 Invalid command

所以,看起来 Discourse 正在明文传输我的凭据,即使在设置中启用了 STARTTLS?这是一个 bug 吗?

我还注意到,当我运行 ./discourse-doctor 时,“YML SETTINGS”摘要顶部列出了以下项目:

==================== YML SETTINGS ====================
DISCOURSE_HOSTNAME=forum.[redacted]
SMTP_ADDRESS=smtp.fastmail.com
DEVELOPER_EMAILS=sysadmin@[redacted]
SMTP_PASSWORD=[redacted]
SMTP_PORT=587
SMTP_USER_NAME=[redacted]@fastmail.fm
LETSENCRYPT_ACCOUNT_EMAIL=

然而,尽管在 app.yml 中设置了 DISCOURSE_SMTP_ENABLE_START_TLS,但没有提及它。不确定这个问题是否相关。

2 个赞

哦,这很奇怪。我手动创建了一个用户帐户(通过 rake admin:create)然后登录,突然电子邮件通知就可以正常工作了。但是,通过 discourse-doctor 发送仍然失败。

也许 discourse-doctor 坏了?

1 个赞

抱歉。我知道那有多令人沮丧。

有可能。它会做一些事情来尝试调试问题所在,所以可能是它使用的逻辑在你的情况下是错误的。

还有一个 rake 任务,对你来说可能更好。

    rake emails:test[x@y.com]

你是否遵循了 新 Discourse 安装上的电子邮件故障排除

2 个赞

我不知道有这个命令,它确实看起来很有用!但结果是一样的:

root@app:/var/www/discourse# rake emails:test redacted@example.com
Testing sending to  using smtp.fastmail.com:587, username:myuser@fastmail.fm with plain auth.
======================================== ERROR ========================================
                                    UNEXPECTED ERROR
500 5.5.1 Invalid command


====================================== SOLUTION =======================================
This is not a common error. No recommended solution exists!

Please report the exact error message above to https://meta.discourse.org/
(And a solution, if you find one!)
=======================================================================================

当我查看 tcpdump 时,我再次看到它在没有 STARTTLS 加密的情况下以明文发送 AUTH PLAIN 凭据。

是的,我浏览了那个页面。

然而,根据 tcpdump 的结果,这在我看来像是诊断工具中的一个 bug,因为即使在 app.yml 中启用了 STARTTLS 设置,它也没有被使用。(Discourse 应用程序本身确实使用了 STARTTLS。我假设许多电子邮件提供商也允许未加密的电子邮件提交,所以这个问题只会出现在那些使用诊断工具 并且 使用了不允许通过 SMTP 进行未加密提交的提供商的人身上。)

1 个赞

啊。看起来那个 rake 任务和 discourse-doctor 调用的是同一个。抱歉。

也许有人可以看看如何让那个 rake 任务更像实际过程,或者至少在它试图弄清楚发生了什么时不要放弃。一个好的第一步是说“嗯,XXX 似乎坏了,但我们会尝试一下……”

1 个赞