The emails:test rake task should not report successful delivery when email is disabled

Similar to Email test area should warn if emails are disabled

This is misleading:

$ 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?
1 Like

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.

1 Like

I agree; that’s a good point. It might be a good idea to send the email and report that email is disabled, just in case.

2 Likes

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
[...]

https://github.com/discourse/discourse/pull/13674

3 Likes

This topic was automatically closed after 21 hours. New replies are no longer allowed.