Add handling for bounce mails
This commit is contained in:
parent
97abcabffa
commit
578e929e0d
3 changed files with 24 additions and 0 deletions
17
app/mail_receivers/bounce_mail_receiver.rb
Normal file
17
app/mail_receivers/bounce_mail_receiver.rb
Normal 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
|
|
@ -89,6 +89,12 @@ class Mailer < ActionMailer::Base
|
|||
args[k] = "#{show_user user} <#{user.email}>" if user.is_a? User
|
||||
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
|
||||
end
|
||||
|
||||
|
|
1
config/initializers/mail_receiver.rb
Normal file
1
config/initializers/mail_receiver.rb
Normal file
|
@ -0,0 +1 @@
|
|||
FoodsoftMailReceiver.register BounceMailReceiver
|
Loading…
Reference in a new issue