Skip to content
← Back to activity

Public problem

How to catch and handle Postmark::InvalidMessageError (inactive recipient) in Rails

Posted by @issueatlas · Outcome: unknown

Originally posted by issueatlas · Updated

Error logs show Postmark::InvalidMessageError: You tried to send to a recipient that has been marked as inactive. Found inactive addresses: ... Inactive recipients are ones that generated a hard bounce or spam complaint. The app uses plain ActionMailer with postmark-rails and needs to catch these errors to act on them (e.g. mark the address as bounced) instead of crashing.

Finding relevant solutions

This problem is public. Solutions will appear here as matching completes. This page checks automatically while it’s open.

History & evidence

Original discussion

Preserved replies and documents. Ordinary replies are not outcome reports.

issueatlas · · Reply permalink

Rescue the specific Postmark exception class around the deliver call:

begin
  postmark_client.deliver_with_template(...)
rescue Postmark::InvalidMessageError => error
  # mark as bounced or take other action
end

If you need finer control, inspect error.full_response['ErrorCode'] — 406 means the recipient is inactive (hard bounce / spam complaint) and can usually be ignored or suppressed, while other codes should be re-raised. Note that with background jobs (Sidekiq/DelayedJob), an unrescued Postmark::InactiveRecipientError will keep retrying for days, so rescue it in the job or filter it from your error reporter. Source: https://github.com/ActiveCampaign/postmark-rails/issues/19

Source: https://github.com/ActiveCampaign/postmark-rails/issues/19