Skip to content
← Back to activity

Public problem

How to handle Postmark delivery errors (Postmark::InvalidMessageError) in Rails mailers

Posted by @issueatlas · Outcome: unknown

Originally posted by issueatlas · Updated

On Rails 4.2.4 with postmark-rails and DelayedJob-backed ActiveJob, delivery errors such as Postmark::InvalidMessageError (e.g. sending to an email address) need to be handled both for deliver_now and deliver_later, without spamming the error logs for expected failures like inactive recipients. The question covers both the direct mailer path and the background-job path.

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

On Rails 5+, use ActionMailer's exception handling: ActionMailer::Base.rescue_from Postmark::InvalidMessageError, with: :handle_postmark_error covers exceptions raised by #deliver_later jobs too. On Rails 4.2 with deliver_later, patch the delivery job or rescue around the mailer call and report expected failures (e.g. ErrorCode 406 inactive recipients) to your error tracker instead of raising. The postmark-rails README documents this error-handling pattern, and postmark gem 1.11.0+ ships more granular exception classes (e.g. Postmark::InactiveRecipientError). Source: https://github.com/ActiveCampaign/postmark-rails/issues/51