Configurazione SMTP non funziona con smtp-relay di GMail

I can’t get SMTP setup working with Discourse and GMail’s SMTP

I enabled SMTP Relay in Google’s settings, allowed sending from my domain (no IP whitelisting), using SMTP auth + encryption.

Discourse is hosted on forum.example.com

DISCOURSE_SMTP_ADDRESS: smtp-relay.gmail.com
DISCOURSE_SMTP_PORT: 587
DISCOURSE_SMTP_USER_NAME: noreply@example.com
DISCOURSE_SMTP_PASSWORD: password
DISCOURSE_SMTP_AUTHENTICATION: login
DISCOURSE_SMTP_DOMAIN: mydomain.io
DISCOURSE_NOTIFICATION_EMAIL: noreply@example.com
DISCOURSE_SMTP_ENABLE_START_TLS: true

I had generic error Job exception: end of file reached, when I added NOTIFICATION_EMAIL and SMTP_DOMAIN envs, now I’m seeing

503 5.5.1 bad sequence of commands x20sm63393lfr.126 - gsmtp

when running doctor and trying to send email to myself.

Changed DISCOURSE_SMTP_DOMAIN to match forum.mydomain.io and still have the same error.

How I’m supposed to debug this further other than changing env, rebuilding and hoping that it works?

Thanks in advance.

Instead of rebuilding you can

./launcher destroy app 
./launcher start app 

There are some topics about getting the Google whatever working. It’s possible, but not easy. And it probably changes every month. :wink:

3 Mi Piace

Sebbene io creda che l’errore di @kvsf sia già stato risolto o che alcune cose fondamentali nella tua configurazione siano state modificate, vorrei continuare questa discussione pubblicando la mia configurazione, il mio ulteriore approccio e la mia richiesta di aiuto nello stesso dominio problematico.

Configurazione di base

  • Google Workspace Business Starter
  • Configura Gmail-Routing > SMTP-Relay con i) solo utenti registrati dall’interno del dominio, ii) IP-whitelisting con l’IP del mio server di hosting del forum e applicazione dell’autenticazione SMTP, iii) applicazione di TLS
  • Installazione di discourse docker secondo la documentazione di discourse
  • Configurazione di app.yml secondo
expose:
  - "80:80"   # http
  - "443:443" # https

env:
  DISCOURSE_HOSTNAME: "forum.mydomain.com"
  DISCOURSE_DEVELOPER_EMAILS: 'dev@mydomain.com'

  DISCOURSE_SMTP_ADDRESS: "smtp-relay.gmail.com"
  DISCOURSE_SMTP_PORT: 587
  DISCOURSE_SMTP_USER_NAME: "user@mydomain.com"
  DISCOURSE_SMTP_PASSWORD: "mypass"
  DISCOURSE_SMTP_ENABLE_START_TLS: true
  DISCOURSE_SMTP_AUTHENTICATION: login
  DISCOURSE_SMTP_OPEN_TIMEOUT: 25
  DISCOURSE_SMTP_READ_TIMEOUT: 25
  DISCOURSE_SMTP_DOMAIN: "mydomain.com"
  DISCOURSE_NOTIFICATION_EMAIL: "noreply@mydomain.com"
  LETSENCRYPT_ACCOUNT_EMAIL: dev@mydomain.com

I miei test

Eseguendo ./discourse-doctor questa configurazione porta all’errore

Testing sending to ...
SMTP server connection successful.
Sending to artificial.testadress@gmail.com. . .
Sending mail failed.
end of file reached

Ho quindi prima controllato i diversi log di discourse e di posta elettronica
Testando manualmente lo stesso processo da docker (connettendosi tramite docker exec -it <CONTAINER_ID> bash) tramite

openssl s_client -starttls smtp -crlf -connect smtp.gmail.com:587

non incontra problemi e funziona bene. Quindi credo che o la mia configurazione dei parametri in app.yml sia strana O discourse internamente abbia una qualche script-miscommunication O… così tante possibilità. ^^
Per non dover sempre eseguire ./launcher rebuild app dopo aver modificato app.yml per testare diverse impostazioni, ho iniziato a modificare direttamente /var/www/discourse/vendor/bundle/ruby/3.2.0/gems/mail-2.8.1/lib/mail/network/delivery_methods/smtp.rb modificando il codice esistente in:

class SMTP
  attr_accessor :settings

  DEFAULTS = {
    :address              => 'smtp-relay.gmail.com',
    :port                 => 587,
    :domain               => 'mydomain.com',
    :user_name            => 'user@mydomain.com',
    :password             => 'mypass',
    :authentication       => 'login',
    :enable_starttls      => nil,
    :enable_starttls_auto => true,
    :openssl_verify_mode  => 'peer',
    :ssl                  => nil,
    :tls                  => nil,
    :open_timeout         => 25,
    :read_timeout         => 25
  }

  def initialize(values)
    self.settings = DEFAULTS #.merge(values)
  end

che porta allo stesso comportamento di cui sopra (impostazioni app.yml personalizzate).

Ricerca di aiuto

E ora sono bloccato. Naturalmente potrei giocare di più con le impostazioni rimanenti (e potrei persino tornare a usare solo SSL, anche se questo è deprecato da discourse), ma vorrei:

  1. imparare come analizzare questo problema più a fondo
  2. comprendere cosa sta realmente succedendo e qual è il problema
  3. risolverlo ed essere in grado di usare tutto senza problemi (+ finalmente far funzionare correttamente il forum)

Grazie in anticipo per il tuo aiuto.

push*
Qualche idea/suggerimento?