Discussione con altri siti web, problema SMTP: fine del file raggiunta

(per lo staff: questo non è correlato all’abbonamento ospitato a cui è associato anche il mio account)

Ho installato Discourse su un VPS seguendo le istruzioni di Run other websites on the same machine as Discourse, ma con questa differenza: ho modificato il file app.yml prima della prima installazione:

sudo mkdir /var/discourse
sudo git clone https://github.com/discourse/discourse_docker.git /var/discourse
cd /var/discourse
sudo cp samples/standalone.yml containers/app.yml
sudo nano containers/app.yml

Nel file YAML ho commentato la sezione delle porte, aggiunto - "templates/web.socketed.template.yml" e impostato hostname e SMTP:

  ## TODO: Il nome di dominio a cui risponderà questa istanza di Discourse
  ## Obbligatorio. Discourse non funzionerà con un semplice indirizzo IP.
  DISCOURSE_HOSTNAME: 'discuss.mydomain.community'

  ## TODO: Elenco di indirizzi email separati da virgola che diventeranno amministratori e sviluppatori
  ## al primo esempio di registrazione 'user1@example.com,user2@example.com'
  DISCOURSE_DEVELOPER_EMAILS: 'someuser@protonmail.com,anotheruser@otherdomain.io'

  ## TODO: Il server SMTP utilizzato per validare nuovi account e inviare notifiche
  # Indirizzo SMTP, nome utente e password sono obbligatori
  # ATTENZIONE: il carattere '#' nella password SMTP può causare problemi!
  DISCOURSE_SMTP_ADDRESS: smtp.myprovider.email
  DISCOURSE_SMTP_PORT: 465
  DISCOURSE_SMTP_USER_NAME: mydomain-no-reply@otherdomain.io
  DISCOURSE_SMTP_PASSWORD: pa$$word
  #DISCOURSE_SMTP_ENABLE_START_TLS: true           # (opzionale, default true)

Poi ho avviato il bootstrap e lanciato l’app di Discourse:

sudo ./launcher bootstrap app
sudo ./launcher start app

Ha funzionato. Ho fermato Discourse e configurato nginx esterno (in /etc/nginx/conf.d/discourse.conf) con la configurazione suggerita solo HTTP (solo per test). Ho potuto accedere a http://discuss.mydomain.community.

Ho fermato Discourse ancora una volta e con certbot ho aggiornato discourse.conf, ottenendo ora:

server {
	server_name discuss.mydomain.community;  # <-- modifica questo

	location / {
		proxy_pass http://unix:/var/discourse/shared/standalone/nginx.http.sock:;
		proxy_set_header Host $http_host;
		proxy_http_version 1.1;
		proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
		proxy_set_header X-Forwarded-Proto $scheme;
		proxy_set_header X-Real-IP $remote_addr;
	}

    listen [::]:443 ssl ipv6only=on; # gestito da Certbot
    listen 443 ssl; # gestito da Certbot
    ssl_certificate /etc/letsencrypt/live/discuss.mydomain.community/fullchain.pem; # gestito da Certbot
    ssl_certificate_key /etc/letsencrypt/live/discuss.mydomain.community/privkey.pem; # gestito da Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # gestito da Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # gestito da Certbot

}
server {
    if ($host = discuss.mydomain.community) {
        return 301 https://$host$request_uri;
    } # gestito da Certbot


	listen 80; listen [::]:80;
	server_name discuss.mydomain.community;
    return 404; # gestito da Certbot
}

Finora, tutto bene. Posso accedere a Discourse via HTTPS (in seguito ho eseguito ./launcher rebuild app quando le cose non funzionavano, ma non ha fatto differenza).

Nella schermata «Completa installazione», dopo aver inviato il modulo di registrazione, ricevo il messaggio «Abbiamo inviato una email di attivazione a someuser@protonmail.com».

Problema: nessuna email arriva.

Nessuna email arriva nella casella di posta dell’amministratore. Ho controllato anche la casella mydomain-no-reply@otherdomain.io, ma non c’è nulla.

Nota: L’intero problema potrebbe essere causato dal fatto che l’utente della posta è su otherdomain.io e dovrebbe risiedere su mydomain.community. Ma per quanto ne so, questo non è un requisito.

Ho iniziato la risoluzione dei problemi e ho testato successivamente con le seguenti modifiche al file app.yml (con un rebuild app in mezzo):

  DISCOURSE_SMTP_ENABLE_START_TLS: false

Nessun successo. Continuo:

## Se vuoi impostare l'indirizzo email "From" per la tua prima registrazione, decommenta e modifica:
  - exec: rails r "SiteSetting.notification_email='mydomain-no-reply@otherdomain.io"

Quindi ho proceduto seguendo Troubleshoot email on a new Discourse install :

  • otherdomain.io ha DKIM e SPF correttamente impostati nel DNS
  • L’uso di telnet dal VPS verso il provider SMTP funziona
  • L’uso di telnet dal contenitore Docker (con docker exec e installazione di telnet) funziona anch’esso

Ho eseguito ./discourse-doctor e ci sono state due parti che hanno attirato l’attenzione (il resto dei risultati era come previsto):

========================================
Versione di Discourse su discuss.mydomain.community: Discourse 2.6.0.beta2 
Versione di Discourse su localhost: NON TROVATA
==================== PROBLEMA DNS ====================
Questo server riporta NON TROVATA, ma discuss.mydomain.community riporta Discourse 2.6.0.beta2 .
Ciò suggerisce che hai un problema DNS o che la colpa è di un proxy intermedio.
Se stai utilizzando Cloudflare o una CDN, potrebbe essere configurata in modo errato.
==================== TEST MAIL ====================
Per un test robusto, ottieni un indirizzo da http://www.mail-tester.com/
Invio di email a REDACTED . . 
Test dell'invio a test-k86jiyqb9@srv1.mail-tester.com usando smtp.myprovider.email:465.
======================================== ERRORE ========================================
                                    ERRORE INASPETTATO

fine file raggiunta

====================================== SOLUZIONE =======================================
Questo non è un errore comune. Non esiste una soluzione raccomandata!

Si prega di segnalare il messaggio di errore esatto sopra a https://meta.discourse.org/
(E una soluzione, se ne trovi una!)

Ho provato due volte. Una volta con l’email configurata, una volta con un indirizzo fornito da mail-tester.com. Stessi risultati. Quindi non sembra buono.

Nota: Apparentemente la procedura di installazione Docker serve anche versioni beta. Buono a sapersi.

Guardando il log di produzione, si legge:

Started GET "/" for REDACTED-IP at 2020-09-03 06:21:57 +0000
Processing by FinishInstallationController#index as HTML
  Rendering finish_installation/index.html.erb within layouts/finish_installation
  Rendered finish_installation/index.html.erb within layouts/finish_installation (Duration: 3.2ms | Allocations: 356)
  Rendered layouts/_head.html.erb (Duration: 15.7ms | Allocations: 2969)
Completed 200 OK in 323ms (Views: 140.3ms | ActiveRecord: 0.0ms | Allocations: 32137)
Started GET "/finish-installation/register" for REDACTED-IP at 2020-09-03 06:22:01 +0000
Processing by FinishInstallationController#register as HTML
  Rendering finish_installation/register.html.erb within layouts/finish_installation
  Rendered finish_installation/register.html.erb within layouts/finish_installation (Duration: 7.1ms | Allocations: 1607)
  Rendered layouts/_head.html.erb (Duration: 22.3ms | Allocations: 3139)
Completed 200 OK in 107ms (Views: 41.3ms | ActiveRecord: 0.0ms | Allocations: 11760)
Started POST "/finish-installation/register" for REDACTED-IP at 2020-09-03 06:22:22 +0000
Processing by FinishInstallationController#register as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"l1hEEsK/gur5yplJdMIHttZAgYcuzLLkESaAI87IMb88nAFqNwi7l3yJ+3EJBw7leFypVGbH4C5hJl7VnJVYBQ==", "email"=>"someuser@protonmail.com", "username"=>"someusername", "password"=>"[FILTERED]", "commit"=>"Register"}
Redirected to https://discuss.mydomain.community/finish-installation/confirm-email
Completed 302 Found in 48ms (ActiveRecord: 0.0ms | Allocations: 4246)
  Rendering layouts/email_template.html.erb
  Rendered layouts/email_template.html.erb (Duration: 0.2ms | Allocations: 31)
Started GET "/finish-installation/confirm-email" for REDACTED-IP at 2020-09-03 06:22:22 +0000
Processing by FinishInstallationController#confirm_email as HTML
  Rendering finish_installation/confirm_email.html.erb within layouts/finish_installation
  Rendered finish_installation/confirm_email.html.erb within layouts/finish_installation (Duration: 2.3ms | Allocations: 418)
  Rendered layouts/_head.html.erb (Duration: 7.9ms | Allocations: 1612)
Completed 200 OK in 25ms (Views: 22.1ms | ActiveRecord: 0.0ms | Allocations: 4611)
Delivered mail ea8af868-4a2c-4312-85dd-f57061a3cd90@discuss.mydomain.community (60015.9ms)
Job exception: Net::ReadTimeout

Ho aspettato un po’ e poi tramite il browser ho richiesto «Reinvia email di notifica». Ecco cosa è stato aggiunto al log di produzione:

Delivered mail 47ca6f15-cd9e-4c96-a670-6646e2bda585@discuss.mydomain.community (60007.9ms)
Job exception: end of file reached

  Rendering layouts/email_template.html.erb
  Rendered layouts/email_template.html.erb (Duration: 0.2ms | Allocations: 31)
Delivered mail 02367872-af3a-4df4-9a68-4e5e7c5eda60@discuss.mydomain.community (60007.4ms)
Job exception: end of file reached

  Rendering layouts/email_template.html.erb
  Rendered layouts/email_template.html.erb (Duration: 0.2ms | Allocations: 31)
Delivered mail ee9ee1fc-6fd1-4970-89fa-260efe2dd04c@discuss.mydomain.community (60014.1ms)
Job exception: end of file reached

  Rendering layouts/email_template.html.erb
  Rendered layouts/email_template.html.erb (Duration: 0.1ms | Allocations: 31)
Delivered mail 9030f87b-99df-4de2-9a60-2c57f7c752de@discuss.mydomain.community (60007.0ms)
Job exception: end of file reached

  Rendering layouts/email_template.html.erb
  Rendered layouts/email_template.html.erb (Duration: 0.2ms | Allocations: 31)
Started PUT "/finish-installation/resend-email" for REDACTED-IP at 2020-09-03 06:31:22 +0000
Processing by FinishInstallationController#resend_email as HTML
  Parameters: {"authenticity_token"=>"NE21scxxyZz3/DxDkoF8kwi9GXoNKvnstNJdKZjQs7afigDKWcbw4XK/XnvvRHTApqExqUUghybE1oPfyo3aDA=="}
  Rendering finish_installation/resend_email.html.erb within layouts/finish_installation
  Rendered finish_installation/resend_email.html.erb within layouts/finish_installation (Duration: 0.9ms | Allocations: 163)
  Rendered layouts/_head.html.erb (Duration: 2.5ms | Allocations: 269)
Completed 200 OK in 63ms (Views: 6.5ms | ActiveRecord: 0.0ms | Allocations: 6408)
  Rendering layouts/email_template.html.erb
  Rendered layouts/email_template.html.erb (Duration: 0.2ms | Allocations: 31)
Delivered mail 127cc350-3fb0-4ef1-8759-391fb407b1cb@discuss.mydomain.community (60008.0ms)
Job exception: Net::ReadTimeout

Delivered mail d9c70dfd-5a8b-4f4c-bafa-5a540fc8ed4f@discuss.mydomain.community (60010.0ms)
Job exception: end of file reached

  Rendering layouts/email_template.html.erb
  Rendered layouts/email_template.html.erb (Duration: 0.1ms | Allocations: 31)
Delivered mail e9e67ed1-d7b1-4e8a-ba11-30501c6fae89@discuss.mydomain.community (60012.4ms)
Job exception: end of file reached

  Rendering layouts/email_template.html.erb
  Rendered layouts/email_template.html.erb (Duration: 0.2ms | Allocations: 31)
  Rendering layouts/email_template.html.erb
  Rendered layouts/email_template.html.erb (Duration: 0.1ms | Allocations: 31)
Delivered mail 82d0361e-0349-4a1a-928e-dcb16dcffdbc@discuss.mydomain.community (60008.6ms)
Job exception: end of file reached

Ho contattato il mio provider di hosting per vedere se il problema fosse dalla loro parte. Hanno detto che, secondo loro, questa configurazione dovrebbe funzionare bene, ma che il VPS non aveva causato alcuna attività sul server SMTP.

Quindi questa è la mia situazione attuale… pubblico su Meta.

Potrebbe essere che il traffico in uscita verso il server di posta sia bloccato? Puoi fare telnet lì? Dall’interno del container?

Sì, riesco a connettermi con successo al server SMTP utilizzando telnet dall’interno del container Docker. Tuttavia, non riesco a inviare un’email di prova con telnet, poiché il mio provider non lo consente (chiude la connessione quando vengono inviati ulteriori comandi).

La soluzione è apparsa semplice. Sebbene il mio provider indichi la porta sopra, ho eseguito un telnet sulla porta 587 e ho trovato che funzionava. Quindi ho modificato app.yml, ho eseguito un rebuild… e tutto ha funzionato correttamente :smiley:

Prima di vedere questo, stavo per raccomandare questa modifica.

La porta 465 è SMTP-over-SSL, che è deprecata.
La porta 587 è la porta MSA (Mail Submission Agent) su cui STARTTLS (aggiornamento da una connessione in chiaro a una connessione TLS) è tipicamente supportata.

Quando avevi la porta 465 nella configurazione, Discourse cercava di comunicare in chiaro su una porta SSL.

Grazie, @supermathie, ho accettato la tua risposta come soluzione. Spiegazione chiara.

Ciao @supermathie

Sembra che la porta 465 sia stata (o sia in fase di) riabilitata secondo la RFC 8314. Il mio attuale provider di posta (mailfence.com) sembra seguire tale raccomandazione.

Esiste un modo per forzare TLS sulla connessione utilizzando la porta 465? Questo dovrebbe risolvere il mio problema, dato che ho verificato con swaks che l’uso di STARTTLS (–tls) fallisce, mentre l’uso di --tls-on-connect (–tlsc) funziona correttamente all’interno del contenitore:

swaks --to user@example.com --from myuser@mailfence.com --server smtp.mailfence.com:465 --auth LOGIN --tlsc --auth-user myuser@mailfence.com

Ciao,

Ah, viene riutilizzata per la sottomissione su TLS, ha senso.

Non al momento. Sembra che ActionMailer supporti questa opzione quando si imposta :ssl = true in smtp_settings, ma al momento non abbiamo un percorso di codice per abilitarlo.

Sono certo che accoglieremmo con piacere una PR che aggiunga tale supporto.