McoreD
McoreD
CDCloudflare Developers
Created by McoreD on 10/19/2023 in #workers-help
Building a simple spam worker
Hi there, I am trying to build a simple spam worker which would go through an array of email domains I maintain, and if the email's domain belongs to this array, then the worker will block it, otherwise I would receive it. I have go it up to so far:
export default {
async email(message, env, ctx) {
const block = ["yourprofithour.com", "modernfinancialhabits.com", "oracleofomahasays.com"]
if (block.indexOf(message.headers.get("from")) == -1) {
await message.forward("[email protected]");
} else {
message.setReject("Address is blocked");
}
}
}
export default {
async email(message, env, ctx) {
const block = ["yourprofithour.com", "modernfinancialhabits.com", "oracleofomahasays.com"]
if (block.indexOf(message.headers.get("from")) == -1) {
await message.forward("[email protected]");
} else {
message.setReject("Address is blocked");
}
}
}
Q1/ The example has the exact email address but I want it to block at domain level. Would above work? Q2/ Instead of having a fixed string for the message.forward can the code detect the original email address the email was sent to, and forward to that address? Q3/ After Save and Delploy, I think I still need to set Action = Send to a Worker, and choose this spam-worker from the Destination drop down, or otherwise I don't think the spam worker is activated. Correct? Appreciate your help.
9 replies