SMTP setup not working with GMail's smtp-relay

While I belief that @kvsf 's error is either already fixed or some fundamental things within your configuration have been changed I would like to continue this thread by posting my own configuration, my further approach and my seek for help within the same problem-domain.

Basic Configuration

  • Google Workspace Business Starter
  • Configure Gmail-Routing > SMTP-Relay with i) only registered users from within domain, ii) IP-whitelisting with my forum-hosting server-IP and enforcing SMTP-Authentification, iii) enforcing TLS
  • discourse docker installation according to discourse-documentation
  • app.yml config according to
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

My Tests

When running ./discourse-doctor this configuration leads to the error

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

I then first checked through the different discourse- and email logs
Manually testing the same process from within docker (by connecting using docker exec -it <CONTAINER_ID> bash) via

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

encounters no problems and works fine. So I believe either my parameter-configuration in the app.yml is odd OR discourse internally has some script-miscommunication OR … so many possibilities. ^^
To not always have to ./launcher rebuild app after changing app.yml to test different settings I started to directly edit /var/www/discourse/vendor/bundle/ruby/3.2.0/gems/mail-2.8.1/lib/mail/network/delivery_methods/smtp.rb by changing the existing code to:

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

which leads to the same behaviour like above (given the customized app.yml) settings.

Search for help

And now I am stuck. Of course I could play more with the left-over settings (and even could switch back to using SSL-only, even though this is deprecated by discourse), but I’d like to:

  1. learn how to analyze this problem deeper and further
  2. thereby understand what is really going on and what is the problem
  3. fix it and be able to use everything smoothly (+finally get the forum running properly)

Thank you for your help in advance.