ksnll
ksnll
CDCloudflare Developers
Created by ksnll on 8/22/2024 in #workers-help
Email worker triggered multiple times for the same email
I have a simple worker that is triggering on a specific email address. This worker does some attachment processing, add some data in d1, then sending an email back to the user. This is all correctly triggered, and this is the end of the handler:
async email(event, env){
console.log("Worker trigger.. this is logged multiple times per same email");
// ... some more work
const msg = createMimeMessage();
msg.setSender({ name: "Name", addr: event.to });
msg.setRecipient(event.from);
msg.setSubject(`Email has been processed`);
msg.setHeader("In-Reply-To", parsedEmail.messageId);
msg.addMessage({
contentType: "text/html",
data: htmlContent,
});

var message = new EmailMessage(event.to, event.from, msg.asRaw());
await event.reply(message);
}
async email(event, env){
console.log("Worker trigger.. this is logged multiple times per same email");
// ... some more work
const msg = createMimeMessage();
msg.setSender({ name: "Name", addr: event.to });
msg.setRecipient(event.from);
msg.setSubject(`Email has been processed`);
msg.setHeader("In-Reply-To", parsedEmail.messageId);
msg.addMessage({
contentType: "text/html",
data: htmlContent,
});

var message = new EmailMessage(event.to, event.from, msg.asRaw());
await event.reply(message);
}
The issue is that sometimes (not always) I get multiple triggers for the same email, in a span of a few hours For example, the original message is processed, then after a few minutes I get another trigger, then after 20 minutes I get another one and so on over a few hours. Has anyone experienced something similar?
5 replies