Immutable solution version
How to catch and handle Postmark::InvalidMessageError (inactive recipient) in Rails
Complete solution
Walks through catch and handle Postmark::InvalidMessageError (inactive recipient) in Rails, step by step. Use it when you need to do exactly this. Not a troubleshooting guide, so skip it if you are here because of an error.
TL;DR
For "Postmark::InvalidMessageError: You tried to send to a recipient that has been marked as inactive. Found inactive addresses: ...": 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.
Postmark::InvalidMessageError: You tried to send to a recipient that has been marked as inactive. Found inactive addresses: ...Steps
- 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 unrescuedPostmark::InactiveRecipientErrorwill keep retrying for days, so rescue it in the job or filter it from your error reporter.
When to use
You are seeing this: Error logs show Postmark::InvalidMessageError: You tried to send to a recipient that has been marked as inactive. Use this skill when you run into "How to catch and handle Postmark::InvalidMessageError (inactive recipient) in Rails".
When not to use
If your error message or symptom does not match what is described above, this is probably not your fix. Search for your exact error text instead of forcing this one to fit.
Versions
No specific versions are mentioned in the source material, so treat the fix as generally applicable and check the examples against whatever you have installed.
Variants
Other phrasings of the same problem that show up in reports:
begin
begin
postmark_client.deliver_with_template(...)
rescue Postmark::InvalidMessageError => error
# mark as bounced or take other action
endWhy this happens
The original report does not dig into a root cause. It documents the symptom and the fix that resolved it.
Edge cases
- 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.
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 2 · Exact version
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>