diff --git a/app/jobs/unqueue_message_job.rb b/app/jobs/unqueue_message_job.rb index 5ce33c8..9cf90fd 100644 --- a/app/jobs/unqueue_message_job.rb +++ b/app/jobs/unqueue_message_job.rb @@ -54,7 +54,7 @@ class UnqueueMessageJob < Postal::Job if queued_message.attempts >= Postal.config.general.maximum_delivery_attempts details = "Maximum number of delivery attempts (#{queued_message.attempts}) has been reached." if queued_message.message.scope == 'incoming' - # Send bounceds to incoming e-mails when they are hard failed + # Send bounces to incoming e-mails when they are hard failed if bounce_id = queued_message.send_bounce details += " Bounce sent to sender (see message )" end @@ -240,7 +240,10 @@ class UnqueueMessageJob < Postal::Job # Log the result log_details = result.details - if result.type =='HardFail' && queued_message.message.send_bounces? + if result.type =='HardFail' && result.suppress_bounce + # The delivery hard failed, but requested that no bounce be sent + log "#{log_prefix} Suppressing bounce message after hard fail" + elsif result.type =='HardFail' && queued_message.message.send_bounces? # If the message is a hard fail, send a bounce message for this message. log "#{log_prefix} Sending a bounce because message hard failed" if bounce_id = queued_message.send_bounce diff --git a/lib/postal/http_sender.rb b/lib/postal/http_sender.rb index c1cb2dd..7ac83c9 100644 --- a/lib/postal/http_sender.rb +++ b/lib/postal/http_sender.rb @@ -43,6 +43,10 @@ module Postal result.type = 'SoftFail' result.retry = true result.connect_error = true + elsif response[:code] == 429 + # Rate limit exceeded, treat as a hard fail and don't send bounces + result.type = 'HardFail' + result.suppress_bounce = true else # This is permanent. Any other error isn't cool with us. result.type = 'HardFail' diff --git a/lib/postal/send_result.rb b/lib/postal/send_result.rb index c61184d..c1788d4 100644 --- a/lib/postal/send_result.rb +++ b/lib/postal/send_result.rb @@ -8,5 +8,6 @@ module Postal attr_accessor :connect_error attr_accessor :log_id attr_accessor :time + attr_accessor :suppress_bounce end end