Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Preventing duplicate emails from being sent

Tags:

email

sendgrid

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.

like image 738
popedotninja Avatar asked Feb 25 '14 06:02

popedotninja


People also ask

How do I stop sending duplicate emails?

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 ].

What causes duplicate emails to be sent?

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.


2 Answers

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.

like image 79
Nick Q. Avatar answered Sep 22 '22 10:09

Nick Q.


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.

like image 36
nahankid Avatar answered Sep 21 '22 10:09

nahankid