How idempotency works
When an email is sent with an idempotency key, Lettermint checks if an email with the same key was already sent within a specific time window. If it was, the duplicate send is prevented.Idempotency is particularly important for queued emails. If a queue job fails and is retried, idempotency ensures the email is only sent once.
Configuration options
Configure idempotency behavior per mailer in yourconfig/mail.php:
Available options
Enable or disable automatic content-based idempotency.
true: Generates idempotency keys based on email contentfalse: Disables automatic idempotency (custom headers still work)
Time window in seconds for deduplication.
- Default:
86400(24 hours to match Lettermint API retention) - Example:
3600for 1 hour,300for 5 minutes - When set to
86400or higher, emails with identical content are permanently deduplicated within the API retention period
Automatic idempotency
Whenidempotency is set to true, the driver automatically generates a unique key based on:
- Email subject, recipients (to, cc, bcc), and content
- Sender address (to differentiate between different sending contexts)
- Time window (if less than 24 hours)
- Identical emails are only sent once within the configured time window
- Retried queue jobs won’t create duplicate emails
- Different emails or the same email after the time window will be sent normally
Example with automatic idempotency
Custom idempotency keys
You can override any configuration by setting a custom idempotency key in the email headers:Custom
Idempotency-Key headers are always respected, even when automatic idempotency is disabled.Priority order
The driver uses idempotency keys in the following priority order:Custom Idempotency-Key header (highest priority)
If the email has an
Idempotency-Key header, it’s always used regardless of configuration.Automatic content-based key
If
idempotency is true in the config, an automatic key is generated from the email content.Idempotency windows
Theidempotency_window determines how long emails are deduplicated:
- 24 hours (default)
- 1 hour
- 5 minutes
Per-email idempotency
You can control idempotency on a per-email basis using custom headers, even when automatic idempotency is disabled:Idempotency with queued emails
When sending emails from queued jobs, idempotency prevents duplicates if the job is retried:With automatic idempotency enabled, the same email content will generate the same key across job retries, preventing duplicates.
Testing idempotency
You can test idempotency behavior in your application:Disabling idempotency
To disable automatic idempotency for a specific mailer:Even with
idempotency: false, custom Idempotency-Key headers in emails are always respected, giving you full control on a per-email basis.