Are Email Workers the same thing as "Rules" (i.e. in gmail,etc.)?

I’m having trouble wrapping my head around “Email Workers”… Can I do the same kinds of things that I do with rules in gmail?

If the subject contains [foo] - or if the sender’s @ddress contains [foo] or if the body of the message contains certain words or phrases…
then do [bar] - where bar might be forwarding the email, moving it to spam, deleting it, sending a rejection/“unknown user” response, etc.

Or am I barking up the wrong tree and need to do that sort of thing client side?

You could do things like that sure, conditionally forward if the from or to address is a certain value, forward specific from/to addresses to specific destinations, reject emails based on those conditions. You do have the full email body as well, but you need to use some parser to parse the email body like PostalMime, example: email_worker_parser/index.js at main · edevil/email_worker_parser · GitHub
You could sort of send it to spam by sending it to a specific address I suppose, like in gmail [email protected], and create a rule to spam all emails coming to that address.

Fundamentally though, unlike Rules, you can just do anything. You have the full message and a Worker’s Environment. You can forward it as normal mail, silently do nothing, reject it, or you can send it to an HTTP Endpoint, or a Queue, or to R2 to be stored, etc, there’s lots more options.

Just a few other ideas: Send your emails to a Discord Webhook, Create a temp email service and use email workers sending to R2/a Durable Object. Cloudflare internally uses it for the new DMARC feature, to parse out dmarc reports and send statistics: GitHub - cloudflare/dmarc-email-worker: DMARC reports processor using Cloudflare Workers and Email Workers

1 Like

Thank you. Most of what you said is way over my head. HTTP Endpoint? R2? Discord Webhook? Durable Object? DMARC? I have no experience with any of that and I’m not really a coder. I think what I really need is an “Email Workers for Dummies” reference with lots of relevant examples.

There are a few examples and docs pages, Email Workers (beta) · Cloudflare Email Routing docs, and the few samples I linked above, but sadly not too much yet, Email Workers themselves are still in beta.

It’s very much a “Developer” or programmer targeted product. Infinitely more flexible than something like Gmail Rules, but requires programming/knowledge. If you are interested in such a thing, I would learn Javascript via one of the many guides/tutorials if you haven’t already, and then there are a few generic Workers guides/tutorials, which Email workers built on top of/the general knowledge would be helpful.

Otherwise, you may want to stick to Rules in Gmail. You can use the Email Routing GUI to add a route to send everything to your Gmail, and then use normal Gmail rules on that mail.

1 Like