chore: Add a condition to handle bounced email (#11873)
Add bounced emails to the conversation thread. Fix Gmail bounce detection by checking the X-Failed-Recipients header. Currently, bounced emails are rejected as auto-replies, which causes support agents to miss important delivery failure context. This PR ensures bounced messages are correctly added to the thread, preserving visibility for the support team.
This commit is contained in:
@@ -4,16 +4,17 @@ module IncomingEmailValidityHelper
|
||||
def incoming_email_from_valid_email?
|
||||
return false unless valid_external_email_for_active_account?
|
||||
|
||||
# Return if email doesn't have a valid sender
|
||||
# This can happen in cases like bounce emails for invalid contact email address
|
||||
return false unless Devise.email_regexp.match?(@processed_mail.original_sender)
|
||||
|
||||
# Process bounced emails, as regular emails
|
||||
return true if @processed_mail.bounced?
|
||||
|
||||
# we skip processing auto reply emails like delivery status notifications
|
||||
# out of office replies, etc.
|
||||
return false if auto_reply_email?
|
||||
|
||||
# return if email doesn't have a valid sender
|
||||
# This can happen in cases like bounce emails for invalid contact email address
|
||||
# TODO: Handle the bounce separately and mark the contact as invalid in case of reply bounces
|
||||
# The returned value could be "\"\"" for some email clients
|
||||
return false unless Devise.email_regexp.match?(@processed_mail.original_sender)
|
||||
|
||||
true
|
||||
end
|
||||
|
||||
|
||||
@@ -157,6 +157,10 @@ class MailPresenter < SimpleDelegator
|
||||
auto_submitted? || x_auto_reply?
|
||||
end
|
||||
|
||||
def bounced?
|
||||
@mail.bounced? || @mail['X-Failed-Recipients'].try(:value).present?
|
||||
end
|
||||
|
||||
def notification_email_from_chatwoot?
|
||||
# notification emails are send via mailer sender email address. so it should match
|
||||
original_sender == Mail::Address.new(ENV.fetch('MAILER_SENDER_EMAIL', 'Chatwoot <accounts@chatwoot.com>')).address
|
||||
|
||||
Reference in New Issue
Block a user