Errore SMTP: è necessario prima inviare un comando 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 Mi Piace

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 Mi Piace

Did you get this working?

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

1 Mi Piace

Sto riscontrando un problema simile. Ieri ho eseguito il debug dell’invio di e-mail su una nuova istanza di Discourse per circa tre ore, senza alcun successo. Sto cercando di inviare e-mail tramite Fastmail con STARTTLS sulla porta 587. Altri servizi funzionano con le stesse credenziali.

Non ricevo l’errore “Must issue a STARTTLS command first” con queste impostazioni:

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

…seguito da un ./launcher rebuild app, quando eseguo ./discourse-doctor e invio un’e-mail, ricevo un errore 500 5.5.1 Invalid command in risposta.

Oggi ho iniziato a tracciare la comunicazione con tcpdump e ho notato che Discourse non sembra utilizzare STARTTLS. Ecco cosa succede quando invio un’e-mail di recupero 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]

Ma con Discourse, succede questo:

< 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

Quindi, sembra che Discourse stia inviando le mie credenziali su Internet in chiaro, anche se STARTTLS è abilitato nelle impostazioni? È un bug?

Ho anche notato che quando eseguo ./discourse-doctor, il riepilogo “YML SETTINGS” in alto elenca i seguenti elementi:

==================== 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=

Tuttavia, non c’è menzione di DISCOURSE_SMTP_ENABLE_START_TLS, anche se è impostato in app.yml. Non sono sicuro se questo problema sia correlato.

2 Mi Piace

Oh, questo è strano. Ho creato un account utente manualmente (tramite rake admin:create) e poi ho effettuato l’accesso, e improvvisamente le notifiche via e-mail hanno funzionato. Tuttavia, l’invio tramite discourse-doctor continua a fallire.

Forse discourse-doctor è rotto?

1 Mi Piace

Mi dispiace. So quanto possa essere frustrante.

È possibile. Fa alcune cose per cercare di diagnosticare qual è il problema, quindi potrebbe essere che la logica che sta usando sia rotta per il tuo caso…

C’è anche un rake task che probabilmente sarebbe stata una scommessa migliore per te.

    rake emails:test[x@y.com]

Stavi seguendo Risoluzione dei problemi di posta elettronica su una nuova installazione di Discourse?

2 Mi Piace

Non ero a conoscenza di quel comando, sembra davvero utile! Il risultato è comunque lo stesso:

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!)
=======================================================================================

Quando guardo tcpdump, vedo di nuovo che sta inviando le credenziali AUTH PLAIN in testo chiaro senza crittografia STARTTLS.

Ho dato un’occhiata a quella pagina, sì.

Tuttavia, basandomi su tcpdump, questo mi sembra un bug negli strumenti di diagnostica perché STARTTLS non viene utilizzato anche se l’impostazione è abilitata in app.yml. (L’applicazione Discourse stessa utilizza STARTTLS. Presumo che molti provider di posta elettronica consentiranno anche l’invio di e-mail non crittografate, quindi questo problema si presenterà solo se qualcuno utilizza gli strumenti di diagnostica e utilizza un provider che non accetta l’invio non crittografato tramite SMTP.)

1 Mi Piace

Ah. Sembra che quel rake task sia lo stesso che chiama discourse-doctor. Mi dispiace per questo.

Forse qualcuno può dare un’occhiata a come rendere quel rake task più simile al processo effettivo, o almeno non arrendersi se i suoi tentativi di capire cosa sta succedendo sono goffi. Un buon primo passo sarebbe dire “Beh, XXX sembra rotto, ma ci proveremo comunque…”

1 Mi Piace