fix(microsoft-shared): make email_oauth_enabled? return true for microsoft_shared
Some checks failed
Lock Threads / action (push) Has been cancelled

ConversationReplyMailer#email_reply guards delivery with:

  return unless smtp_config_set_or_development? || email_smtp_enabled?
                || (email_imap_enabled? && email_oauth_enabled?)

email_oauth_enabled? in the upstream helper only recognises microsoft? and
google? providers. For our new microsoft_shared provider it returns false,
so the guard fails:
  - smtp_config_set_or_development?  false (production, no SMTP_ADDRESS)
  - email_smtp_enabled?              false (we never set channel.smtp_enabled)
  - email_imap_enabled?              true  (we set imap_enabled in callback)
  - email_oauth_enabled?             false (channel.microsoft? is false)

email_reply early-returns without calling mail(). ActionMailer ends up
with no Mail::Message, deliver_now returns nil, and the next line in
Email::SendOnEmailService raises 'undefined method message_id for nil'.

Override email_oauth_enabled? in the overlay to return true for
microsoft_shared channels.
This commit is contained in:
netlas
2026-04-28 11:47:50 +03:00
parent 235b990ef9
commit c1c05429a8

View File

@@ -1,4 +1,16 @@
module Custom::Leadchat::ConversationReplyMailerHelperExtension
# Treat microsoft_shared channels as OAuth-enabled email channels so the
# email_reply mailer action's gate guard
# return unless ... || (email_imap_enabled? && email_oauth_enabled?)
# passes for them. Without this the mailer returns early, no mail is built,
# deliver_now returns nil, and Email::SendOnEmailService crashes calling
# .message_id on nil.
def email_oauth_enabled?
return true if @channel.respond_to?(:microsoft_shared?) && @channel&.microsoft_shared?
super
end
# Override the OAuth SMTP routing path for microsoft_shared channels. Each
# channel's provider_config['transport'] decides which delivery method runs:
#