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.
Open the “Prevent to send duplicated emails to recipients with the same address” (“PreventDuplicatesSending” code) system setting and select the [ Default value ] checkbox on the opened page. Click [ Save ].
Network and server problems If you are receiving duplicates of only some of your mail, the cause may be technical difficulty along the delivery path. Either a network connection is having problems, or one of the computers along the route is very slow or having other system problems.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With