Skip to content

Instantly share code, notes, and snippets.

@Lejo1
Created February 6, 2023 11:26
Show Gist options
  • Save Lejo1/92fb60095ddea5b5fb78da6f00d78a59 to your computer and use it in GitHub Desktop.
Save Lejo1/92fb60095ddea5b5fb78da6f00d78a59 to your computer and use it in GitHub Desktop.
Listmonk Bounce Processing using Cloudflare Route to workers.yml
const fromAdress = "[email protected]";
const webhook = "https://listmonk.example.com/webhooks/bounce";
const auth = "user:password";
export default {
async email(message, env, ctx) {
if (message.from != fromAdress) {
message.setReject("This is a Noreply Address");
return;
}
let rawEmail = new Response(message.raw)
let body = await rawEmail.text()
// Match original receipient in bounce Mail
let toMail = new RegExp("(?<=Original-Recipient: rfc822;).*?(?=\\r\\n)").exec(body);
console.log(toMail);
if (!toMail) {
message.setReject("No bounce mail found");
return;
}
let data = {"email": toMail[0], "source": "CloudflareWorker", "type": "hard"};
// Optionaly Match campaignUuid
let campaignUuid = new RegExp("(?<=X-Listmonk-Campaign: ).*?(?=\\r\\n)").exec(body);
if (campaignUuid) {
data["campaign_uuid"] = campaignUuid[0];
}
await fetch(webhook, {
method: "POST",
headers: {
"Content-Type": "application/json",
"Authorization": "Basic " + btoa(auth)
},
body: JSON.stringify(data)
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment