# SMTP错误：必须先发出STARTTLS命令

**URL:** https://meta.discourse.org/t/smtp-error-must-issue-a-starttls-command-first/181050
**Category:** Self-hosting
**Created:** [2021年二月24日 21:16 UTC](https://meta.discourse.org/t/smtp-error-must-issue-a-starttls-command-first/181050 "2021-02-24T21:16:33Z")
**Posts on this page:** 1
**Showing post:** 6

<div class="post-metadata">

### Author: ![dbrgn](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/dbrgn/32/240704_2.png) [@dbrgn](https://meta.discourse.org/u/dbrgn)
#### Post date: [2021年十一月22日 08:25 UTC](https://meta.discourse.org/t/smtp-error-must-issue-a-starttls-command-first/181050/6 "2021-11-22T08:25:01Z")

</div>

我遇到了类似的问题。昨天我花了大约三个小时调试新 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`，但没有提及它。不确定这个问题是否相关。

---

_[View the full topic](https://meta.discourse.org/t/smtp-error-must-issue-a-starttls-command-first/181050)._
