Email configuration debugging

Hello, we have Discourse running on our VPS (tutorial) behind NGINX, as it described here.

We would like to use SMTP server of Beget (https://beget.com/en) provider but email sending does not work. We don’t have enough debug information to solve this problem by ourselves.
We tried different settings and rebuild the app after each change.

Configuration (part of app.yml)
DISCOURSE_SMTP_ADDRESS: smtp.beget.com
DISCOURSE_SMTP_PORT: 465
DISCOURSE_SMTP_USER_NAME: discourse@redforester.com
DISCOURSE_SMTP_PASSWORD: "edited-password"
DISCOURSE_SMTP_ENABLE_START_TLS: true           # (optional, default true)
DISCOURSE_SMTP_AUTHENTICATION: "login"
DISCOURSE_SMTP_OPENSSL_VERIFY_MODE: "none"
Output from discourse-doctor
DISCOURSE_HOSTNAME=discourse.redforester.com
SMTP_ADDRESS=smtp.beget.com
DEVELOPER_EMAILS=REDACTED 
SMTP_PASSWORD=REDACTED 
SMTP_PORT=465
SMTP_USER_NAME=discourse@redforester.com

==================== MAIL TEST ====================
For a robust test, get an address from http://www.mail-tester.com/
Sending mail to REDACTED  . . 
Testing sending to strangecamelcaselogin@gmail.com using discourse@redforester.com:edited-password@smtp.beget.com:465.
======================================== ERROR ========================================
                                    UNEXPECTED ERROR

Net::ReadTimeout

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

==================== DONE! ====================

So:

  • Without DISCOURSE_SMTP_OPENSSL_VERIFY_MODE variable or with it and "none" value nothing changes - "Net::ReadTimeout"
  • Without DISCOURSE_SMTP_AUTHENTICATION: "login" we get same error - “Net::ReadTimeout”.
  • Changing DISCOURSE_SMTP_PORT to 25/2525 with DISCOURSE_SMTP_ENABLE_START_TLS: false - "504 PLAIN authentication mechanism not supported". (DISCOURSE_SMTP_AUTHENTICATION is set to “login”, I can see this value in admin area)
  • Changing DISCOURSE_SMTP_PORT to 25/2525 with DISCOURSE_SMTP_ENABLE_START_TLS: true - same "504 PLAIN authentication mechanism not supported". (DISCOURSE_SMTP_AUTHENTICATION is set to “login”, I can see this value in admin area)
  • Python script with different settings (port 25/465, with or without SSL) works fine on host and inside Discourse docker container.
Python code
import smtplib


def notify(server_account, target, message):
    server, login, password = server_account

    msgbox = smtplib.SMTP(server, port=25)

    msgbox.user = login
    msgbox.password = password
    msgbox.ehlo_or_helo_if_needed()
    msgbox.auth('LOGIN', msgbox.auth_login, initial_response_ok=True)
    msgbox.sendmail(login, target, message)
    msgbox.quit()


if __name__ == '__main__':
    smtp_server = 'smtp.beget.com'
    sender = 'discourse@redforester.com'  # sender email
    password = 'edited-password'  # password

    server_account = (smtp_server, sender, password)

    target = 'strangecamelcaselogin@gmail.com'  # target email

    subject = 'discourse test'
    body = '0049'
    message = """From: {0}\r\nTo: {1}\r\nSubject: {2}\r\n\r\n{3}""".format(sender, target, subject, body)

    notify(server_account, target, message)

But how can we debug deeper? Log file shared/standalone/log/rails/production.log does not contain any helpful information.

We also tried to follow this:

So, we moved on to Mailgun and its works fine. Looks like no one should use unpopular, but trusted services due to lack of troubleshooting abilities.

1 Like