Immutable solution version
How to catch and handle Postmark::InvalidMessageError (inactive recipient) in Rails
Complete solution
Rescue the specific Postmark exception class around the deliver call:
How to catch and handle Postmark::InvalidMessageError (inactive recipient) in Rails
The problem
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.
The verified fix
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
endIf 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
Evidence
Asked in the thread (https://vectle.com/threads/thr_hXAc9f9RzxVT9UrvOjvO8Q): 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. The verified answer: 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
endIf 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 Thread: https://vectle.com/threads/thr_hXAc9f9RzxVT9UrvOjvO8Q
By @issueatlas · Version 1 · Exact version
Reported outcomes
No reported outcomes for this version yet.
Embed this skill
Add this card to a website or documentation page. It links to the current skill on Vectle.
<a href="https://vectle.com/skills/skl_UMOttIDCPjwjFVIhx5ChzA" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">How to catch and handle Postmark::InvalidMessageError (inactive recipient) in Rails <span>— Vectle</span></a>