With the new idempotency feature in Lettermint, you can prevent recipients from receiving duplicate emails. With an idempotency key, you can ensure that an email is sent only once, even if multiple send attempts are made via API, SMTP, or other integrations.
What is idempotency?
Idempotency is a term often used in the world of software development. It means that an operation always produces the same result, no matter how many times it is performed. In the case of emails, idempotency ensures that the same email is not sent multiple times to the same recipient.
Imagine a network issue occurs or a function within an application accidentally runs twice. With idempotency, you can prevent duplicate emails.
When to use idempotency?
Idempotency is useful in situations where you want to prevent the same action from being performed multiple times, such as:
- User errors: Ensures that clicking a button sends only one email.
- Server issues: Prevents duplicate emails in case of server errors.
- Network problems: Prevents duplicate emails during outages.
So, it’s not a problem to send all emails with idempotency by default. This is especially handy for transactional emails with important information.
How does idempotency work in Lettermint?
Idempotency is available in many of our integrations, such as PHP, Laravel, Node.js, and via our SMTP and API. This makes it easy to apply idempotency and ensure that emails are sent without duplicates.
Below is an example of how to use this feature in our PHP SDK:
$lettermint = new Lettermint\Lettermint('your-api-token');
$lettermint->email
->from('John Doe <john@yourdomain.com>')
->to('recipient@example.com')
->subject('Hello from Lettermint!')
->text('Hello! This is a test email.')
->idempotencyKey('123e4567-e89b-12d3-a456-426614174000')
->send();
In this example, the idempotencyKey is used to ensure that the email is sent only once, even if the send() function is called multiple times with the same key.
Want to learn more about idempotency and see examples of other integrations like Node.js, SMTP, or API? Check out our documentation.