The discussion addresses a bug where the emails:test rake task misleadingly reports successful email delivery even when emails are disabled via SiteSetting.disable_emails == "non-staff". supermathie highlights the issue and suggests either modifying Email::Sender#send to return delivery status or adding a warning in the rake task. pfaffman proposes ignoring the disable_emails setting for test purposes, since console access implies administrative intent. supermathie agrees and suggests sending the email anyway while still warning about the disabled setting. riking implemented a fix that now only reports success if an EmailLog is created, and adds a clear warning when disable_emails is active. The fix ensures the task accurately reflects whether mail was sent and improves troubleshooting by prompting users to adjust the setting if needed. The PR implementing this is available at https://github.com/discourse/discourse/pull/13674.
$ rake 'emails:test[michael@example.com]'
Testing sending to michael@example.com using mx-out:25.
SMTP server connection successful.
Sending to michael@example.com. . .
Mail accepted by SMTP server.
If you do not receive the message, check your SPAM folder
or test again using a service like http://www.mail-tester.com/.
If the message is not delivered it is not a problem with Discourse.
Check the SMTP server logs to see why it failed to deliver the message.
In this case, no email was sent since SiteSetting.disable_emails == "non-staff".
We should warn about this in the rake task. Do we want to:
add logic to Email::Sender#send that returns a value indicating whether the message was sent (e.g. sent, skipped, disabled, no_message)
or, add logic to the emails:test task that tests only for disable_emails?
I think I had something to do with some of that code…
So the bit about the mail being accepted is a lie?
What I would most want is for the rake task to ignore the disable emails setting. If someone has access to the console then they should be able to send a test email.
I couldn’t repro the message not sending due to SiteSetting.disable_emails, but I did change the script to only report success if an EmailLog was returned, and an extra warning for the disable_emails setting.
$ bin/rake 'emails:test[]'
Testing sending to using localhost:1025, username: with auth.
SMTP server connection successful.
Sending to . . .
Mail was not sent.
Reason: message.to is blank
### WARNING
The `disable_emails` site setting is currently set to non-staff.
Consider changing it to 'no' before performing any further troubleshooting.
and
Sending to michael@example.com. . .
Mail accepted by SMTP server.
Message-ID: dfaf1c88-aab6-474b-b50c-8c500afb6291@localhost
If you do not receive the message, check your SPAM folder
[...]