DEV: Add service to validate email settings (PR #13021)

We have a few places in the code where we need to validate various email related settings, and will have another soon with the improved group email settings UI. This PR introduces a class which can validate POP3, IMAP, and SMTP credentials and also provide a friendly error message for issues if they must be presented to an end user. As part of this, I am changing POP3 validation and the email test rake task to use the new validator.


What do you think about allowlisting potential exceptions? Something like

class EmailSettingsValidator
  FRIENDLY_EXCEPTIONS = [Net::POPAuthenticationError, Net::IMAP::NoResponseError...]

And then rescue can look like


Not sure if that would work, but it would be nice to not have blank rescue

also if we have FRIENDLY_EXCEPTIONS constant we would be able to add a guard to raise an error when an exception is not expected:

raise if !FRIENDLY_EXCEPTIONS.include?(exception.class)

I don’t follow that, why do we need to settings for?

Ah I guess I don’t need that for now, will add that in a later PR, it is for autofilling the settings in the UI

Ah yes that makes sense, will add that

I just want to have the blank rescue there just in case we get an error we are not expecting, because this friendly message method is meant to be used to return a message back to the user.

It might be not friendly anymore, but I understand your point :slight_smile: