Mail test failure in discourse-doctor

I am trying to troubleshoot SMTP problems using ./discourse-doctor

The closest related issue I could find is Yet other SMTP 587 port email various errors.

Before implementing the suggestions, I got consistent timeout.

After configuring:

DISCOURSE_SMTP_FORCE_TLS: true
DISCOURSE_SMTP_ENABLE_START_TLS: false

I get the following from discourse-doctor:

==================== MAIL TEST ====================
For a robust test, get an address from http://www.mail-tester.com/
Or just send a test message to yourself.
Email address for mail test? ('n' to skip) [admin@burlyqna.org]:
Sending mail to admin@burlyqna.org. . .
Testing sending to admin@burlyqna.org using smtp.mailfence.com:465, username:philion@mailfence.com with plain auth.
SMTP server connection successful.
Sending to admin@burlyqna.org. . .
Sending mail failed.
end of file reached

See: http://talk.burlyqna.org/NjdhMDAwYTk4NmM3MmM1.txt

I am able to externally validate the SMTP server config with:

swaks --to philion@gmail.com --from admin@burlyqna.org --server smtp.mailfence.com:465 --auth LOGIN --tlsc --auth-user philion@mailfence.com

Any clues how SMTP server connection successful. but Sending mail failed.?

Many thanks,
Paul

1 Like

For TLS you should use port 587?

I would try to add puts error.backtrace (or similar) after

and rerun discourse-doctor.

1 Like

This is what our auto responder came up with, I think trying smtp domain is probably worth a shot.

1 Like

Thomas,

There is a lot of discussion about 465 in the support forums. Based on my reading, it looks like Discourse makes a lot of assumptions about SSL and TLS over SMTP, and there are a handful of env vars that control the detailed behaviors.

HOWEVER, given the number of reported errors and related questions in these forums, I have the strong impression that these settings are poorly documented and difficult to use. And seeing similar problems going back to 2017, this has been an issue for years now.

Searches for “port 465” or “Net::ReadTimeout smtp” can reveal a long list of similar issues.

I’ll give this a try. Thanks!

Thomas,

I’m trying to find this file on the docker build, and I can’t. I see that it’s wrapped in a container, but I’ve cloned discourse/discourse_docker not discourse/discourse.

When I try to enter the app with launcher enter app, there’s no way to edit that file or to install vi.

I cannot find any docs or flags for running ./discourse-doctor with debug logs turned on.

Fails in the same way: Can’t send email, ./discourse-doctor reports the same error.

Updated app.yml as suggest, rebuilt app (no email), tried ./discourse-doctor and got the same error message.

./launcher enter  app
sudo apt update && sudo apt install neovim -y

should help.

Thanks! I’m getting pretty long-in-the-tooth when I can’t “sudo apt install vi”. I have to remember it’s called neovim now.

Given the suggested change to dump stack trace, I offer:http://talk.burlyqna.org/ODgyZjg5Y2QyMTU1ZmEx.txt

The relevant snippet:

/var/www/discourse/vendor/bundle/ruby/3.3.0/gems/net-protocol-0.2.2/lib/net/protocol.rb:237:in `rbuf_fill'
/var/www/discourse/vendor/bundle/ruby/3.3.0/gems/net-protocol-0.2.2/lib/net/protocol.rb:199:in `readuntil'
/var/www/discourse/vendor/bundle/ruby/3.3.0/gems/net-protocol-0.2.2/lib/net/protocol.rb:209:in `readline'
/var/www/discourse/vendor/bundle/ruby/3.3.0/gems/net-smtp-0.5.1/lib/net/smtp.rb:1017:in `recv_response'
/var/www/discourse/vendor/bundle/ruby/3.3.0/gems/net-smtp-0.5.1/lib/net/smtp.rb:1008:in `block in getok'
/var/www/discourse/vendor/bundle/ruby/3.3.0/gems/net-smtp-0.5.1/lib/net/smtp.rb:1027:in `critical'
/var/www/discourse/vendor/bundle/ruby/3.3.0/gems/net-smtp-0.5.1/lib/net/smtp.rb:1006:in `getok'
/var/www/discourse/vendor/bundle/ruby/3.3.0/gems/net-smtp-0.5.1/lib/net/smtp.rb:986:in `quit'
/var/www/discourse/vendor/bundle/ruby/3.3.0/gems/net-smtp-0.5.1/lib/net/smtp.rb:732:in `do_finish'
/var/www/discourse/vendor/bundle/ruby/3.3.0/gems/net-smtp-0.5.1/lib/net/smtp.rb:645:in `ensure in start'
/var/www/discourse/vendor/bundle/ruby/3.3.0/gems/net-smtp-0.5.1/lib/net/smtp.rb:645:in `start'
/var/www/discourse/vendor/bundle/ruby/3.3.0/gems/mail-2.8.1/lib/mail/network/delivery_methods/smtp.rb:109:in `start_smtp_session'
/var/www/discourse/vendor/bundle/ruby/3.3.0/gems/mail-2.8.1/lib/mail/network/delivery_methods/smtp.rb:100:in `deliver!'
/var/www/discourse/vendor/bundle/ruby/3.3.0/gems/mail-2.8.1/lib/mail/message.rb:269:in `deliver!'
/usr/local/lib/ruby/3.3.0/delegate.rb:87:in `method_missing'
/var/www/discourse/lib/email/sender.rb:296:in `send'

Seems like the other side terminated the connection.

btw: http://talk.burlyqna.org/NjdhMDAwYTk4NmM3MmM1.txt is not available any more

1 Like

Do those log files get retained when I rebuild?

I updated passwords to remove symbols, waited for the SMTP auth propagation delay (long enough to make lunch), confirmed proper creds to correctly send email with swaks, and…

Same error.

I notice rebuilding removes the stacktrace dump, so I’m going to add that back and try ./launcher destroy app && ./launcher start app

1 Like

Installed debug trace, ran doctor:
http://talk.burlyqna.org/NWQ5MjBlMTIwN2JiNGNl.txt

==================== MAIL TEST ====================
For a robust test, get an address from http://www.mail-tester.com/
Or just send a test message to yourself.
Email address for mail test? ('n' to skip) [admin@burlyqna.org]:
Sending mail to admin@burlyqna.org. . .
Testing sending to admin@burlyqna.org using smtp.mailfence.com:465, username:philion with plain auth.
SMTP server connection successful.
Sending to admin@burlyqna.org. . .
Sending mail failed.
end of file reached
/var/www/discourse/vendor/bundle/ruby/3.3.0/gems/net-protocol-0.2.2/lib/net/protocol.rb:237:in `rbuf_fill'
/var/www/discourse/vendor/bundle/ruby/3.3.0/gems/net-protocol-0.2.2/lib/net/protocol.rb:199:in `readuntil'
/var/www/discourse/vendor/bundle/ruby/3.3.0/gems/net-protocol-0.2.2/lib/net/protocol.rb:209:in `readline'
/var/www/discourse/vendor/bundle/ruby/3.3.0/gems/net-smtp-0.5.1/lib/net/smtp.rb:1017:in `recv_response'
/var/www/discourse/vendor/bundle/ruby/3.3.0/gems/net-smtp-0.5.1/lib/net/smtp.rb:1008:in `block in getok'
/var/www/discourse/vendor/bundle/ruby/3.3.0/gems/net-smtp-0.5.1/lib/net/smtp.rb:1027:in `critical'
/var/www/discourse/vendor/bundle/ruby/3.3.0/gems/net-smtp-0.5.1/lib/net/smtp.rb:1006:in `getok'
/var/www/discourse/vendor/bundle/ruby/3.3.0/gems/net-smtp-0.5.1/lib/net/smtp.rb:986:in `quit'
/var/www/discourse/vendor/bundle/ruby/3.3.0/gems/net-smtp-0.5.1/lib/net/smtp.rb:732:in `do_finish'
/var/www/discourse/vendor/bundle/ruby/3.3.0/gems/net-smtp-0.5.1/lib/net/smtp.rb:645:in `ensure in start'
/var/www/discourse/vendor/bundle/ruby/3.3.0/gems/net-smtp-0.5.1/lib/net/smtp.rb:645:in `start'
/var/www/discourse/vendor/bundle/ruby/3.3.0/gems/mail-2.8.1/lib/mail/network/delivery_methods/smtp.rb:109:in `start_smtp_session'
/var/www/discourse/vendor/bundle/ruby/3.3.0/gems/mail-2.8.1/lib/mail/network/delivery_methods/smtp.rb:100:in `deliver!'
/var/www/discourse/vendor/bundle/ruby/3.3.0/gems/mail-2.8.1/lib/mail/message.rb:269:in `deliver!'

Did you try using your full email as login name?

Updated app.yml to use full email as user, redeployed with ./launcher destroy app && ./launcher start app.

Same error: http://talk.burlyqna.org/ZDg1YWE1YTA2YWU1Zjhj.txt

Destroy and start also wiped out the debug, but I’m going to assume the same issue:

case rv = @io.read_nonblock(BUFSIZE, tmp, exception: false)

returns a nil, and that results in a EOF and non/error response.

After a lot of testing, and a lot of help from @thoka, I offer the following summary:

I am able to run SMTP tests using the same creds that I have supplied container/app.yml that work with both swaks (Swaks - Swiss Army Knife for SMTP) and sample Ruby code provide by @thoka (see below).

These work consistently. However, trying to standup a Discourse server (which cannot send the initial email to the admin user) or using discourse-doctor bot result in email failures:

==================== MAIL TEST ====================
For a robust test, get an address from http://www.mail-tester.com/
Or just send a test message to yourself.
Email address for mail test? ('n' to skip) [admin@burlyqna.org]:
Sending mail to admin@burlyqna.org. . .
Testing sending to admin@burlyqna.org using smtp.mailfence.com:465, username:xxx@mailfence.com with plain auth.
SMTP server connection successful.
Sending to admin@burlyqna.org. . .
Sending mail failed.
end of file reached

This seems to be a protocol config failure, as I’m able send test emails using standard Ruby tools:

require 'mail'

SMTP_SERVER = 'smtp.mailfence.com'
SMTP_PORT = 465
USERNAME = 'xyz'
PASSWORD = '...'

FROM = 'admin@burlyqna.org'
TO = 'testing@gmail.com'
SUBJECT = 'Test from Ruby'

BODY = "Hello,\n\nThis is a test email sent from Ruby over a SSL-secured connection.\n\nBest regards!"

Mail.defaults do
  delivery_method :smtp, {
    address: SMTP_SERVER,
    port: SMTP_PORT,
    user_name: USERNAME,
    password: PASSWORD,
    domain: "burlyqna.org",
    enable_starttls_auto: :false,
    authentication: :plain,
    ssl: true,
  }
end

begin
  puts 'Sending email...'
  puts "SMTP_SERVER: #{SMTP_SERVER}"
  puts "SMTP_PORT: #{SMTP_PORT}"
  puts "USERNAME: #{USERNAME}"
  puts "PASSWORD: #{PASSWORD}"
  puts "FROM: #{FROM}"
  puts "TO: #{TO}"

  mail = Mail.new do
    to TO
    from FROM
    subject SUBJECT
    body BODY
  end

  mail.deliver!
end

The current SMTP settings in my app.yml are:

DISCOURSE_SMTP_ADDRESS: smtp.mailfence.com
DISCOURSE_SMTP_PORT: 465
DISCOURSE_SMTP_USER_NAME: xxx@mailfence.com
DISCOURSE_SMTP_PASSWORD: '...'
DISCOURSE_SMTP_FORCE_TLS: true                   # https://meta.discourse.org/t/cannot-send-email-problem-with-port-465/246004/8
DISCOURSE_SMTP_ENABLE_START_TLS: false           # (optional, default true)
DISCOURSE_SMTP_DOMAIN: burlyqna.org              # (required by some providers)
DISCOURSE_NOTIFICATION_EMAIL: noreply@talk.burlyqna.org
1 Like