FIX: Do not enqueue :group_smtp_email job if IMAP disabled for the group (PR #13307)

When a group only has SMTP enabled and not IMAP, we do not want to enqueue the :group_smtp_email job because using the group’s SMTP credentials for sending user_private_message emails is handled by the UserNotifications class.

We do not want the :group_smtp_email job to be enqueued because that uses a reply key instead of the group.email_username for the reply-to address which is not what we want for SMTP only, and also creates an IncomingEmail record to prevent IMAP double syncing which we do not need either.

There is an open question about what happens when IMAP is enabled after SMTP has been enabled for a while, and also questions around whether we could do away with :group_smtp_email altogether and handle everything via EmailLog and UserNotifications, adding additional columns to the former and modifying the Imap::Sync class to take this into account…a lot more further testing for IMAP needs to be done to answer those questions.

For now, this fix should be sufficient to get the correct reply-to address for user_private_response messages sent in response to emails sent directly to the group’s email_username SMTP address.


The title of this pull request changed from “FIX: Do not enqueue :group_smtp_email job if IMAP disabled” to "FIX: Do not enqueue :group_smtp_email job if IMAP disabled for the group

Sorry I moved this method at the same time…change is adding !SiteSetting.enable_imap and imap_enabled: true to the group query

      group.update!(imap_enabled: false)