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インスタンスでメール送信のデバッグに約3時間費やしましたが、成功しませんでした。ポート587でSTARTTLS経由でFastmail経由でメールを送信しようとしています。同じ認証情報で他のサービスは動作しています。

これらの設定で「Must issue a STARTTLS command first」というエラー応答は得られません。

    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が有効になっているにもかかわらず、認証情報を平文でインターネットに送信しているようです。これはバグでしょうか?

また、./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]

Troubleshooting email on a new Discourse installに従っていましたか?

「いいね!」 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 =======================================
これは一般的なエラーではありません。推奨される解決策はありません!
上記の正確なエラーメッセージを https://meta.discourse.org/ に報告してください。
(見つけた場合は、解決策も!)
=======================================================================================

tcpdumpを見ると、STARTTLS暗号化なしで、AUTH PLAIN認証情報がプレーンテキストで送信されていることが再び確認できます。

はい、そのページを見ました。

しかし、tcpdumpに基づくと、これは診断ツールのバグのように思われます。なぜなら、app.ymlで設定が有効になっているにもかかわらず、STARTTLSが使用されていないからです。(Discourseアプリケーション自体はSTARTTLSを使用しています。多くのメールプロバイダーは、暗号化されていないメール送信も許可していると推測されるため、この問題は、診断ツールを使用し、かつSMTP経由での暗号化されていない送信を受け付けないプロバイダーを使用した場合にのみ発生するでしょう。)

「いいね!」 1

ああ。そのrakeタスクはdiscourse-doctorが呼び出すものと同じようです。申し訳ありません。

もしかしたら、誰かがそのrakeタスクを実際のプロセスに似せる方法、あるいは少なくともそれが状況を把握しようとする試みが不器用な場合に諦めないようにする方法を見つけられるかもしれません。まず最初に行うべきことは、「さて、XXXは壊れているようですが、とにかく試してみましょう…」と言うことでしょう。

「いいね!」 1