Question

I'm building a web application where a user clicks a button, and that click sends an email. On a flaky connection, sometimes the user will click the button multiple times, which causes multiple email to be sent. The email is being sent via SMTP via Sendgrid.

Is there a technique that can be used to only send a single email if the same request parameters are submitted multiple times? I know how to prevent multiple submissions on something like a web form on my own application, but I'm not sure how to do the same thing w/ a 3rd party email API.

Was it helpful?

Solution

To prevent multiple submissions to SendGrid (or most APIs), you'll need to set up something on your end that stores each submission and makes sure that the same thing hasn't already been sent.

If you're looking to simply prevent multiple submissions of the same data from the same user, you could store hashes of recent submissions in memory and compare them or something similar.

However, the best option is likely just to do something client side that prevents a user from clicking a button twice.

OTHER TIPS

If you're using Mailjet, you could use X-Mailjet-DeduplicateCampaign header, which would block/unblock messages to be sent multiple times inside one campaign to the same contact.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top