Add handling for bounce mails

This commit is contained in:
Patrick Gansterer 2017-08-19 16:24:02 +02:00
parent 97abcabffa
commit 578e929e0d
3 changed files with 24 additions and 0 deletions

View file

@ -0,0 +1,17 @@
class BounceMailReceiver
def self.regexp
/bounce\+(?<local>.*)=(?<domain>[^=]+)/
end
def received(match, data)
address = "#{match[:local]}@#{match[:domain]}"
mail = Mail.new data
subject = mail.subject || 'Unknown bounce error'
MailDeliveryStatus.create email: address,
message: subject,
attachment_mime: 'message/rfc822',
attachment_data: data
end
end

View file

@ -89,6 +89,12 @@ class Mailer < ActionMailer::Base
args[k] = "#{show_user user} <#{user.email}>" if user.is_a? User args[k] = "#{show_user user} <#{user.email}>" if user.is_a? User
end end
reply_email_domain = FoodsoftConfig[:reply_email_domain]
if reply_email_domain && !args[:return_path]
address = Mail::Parsers::AddressListsParser.new.parse(args[:to]).addresses.first
args[:return_path] = "<#{FoodsoftConfig.scope}.bounce+#{address.local}=#{address.domain}@#{reply_email_domain}>"
end
super super
end end

View file

@ -0,0 +1 @@
FoodsoftMailReceiver.register BounceMailReceiver