Yes, you can write it locally, but afaik

Yes, you can write it locally, but afaik it can't actually be tested(unless you pass in the args yourself)
21 Replies
Dovid G
Dovid G7mo ago
How do I configure the worker locally in Wrangler to indicate to Cloudflare that its a Email Worker?
Hello, I’m Allie!
Cloudflare Docs
Configuration - Wrangler · Cloudflare Workers docs
Use a wrangler.toml configuration file to customize the development and deployment setup for your Worker project and other Developer Platform …
Dovid G
Dovid G7mo ago
That seems to be for configuring regular Worker to be able to send emails to verified addresses but not for routing incoming emails?
Hello, I’m Allie!
It doesn't look like it The config parser only shows options for send_email
Dovid G
Dovid G7mo ago
I just found in docs:
EmailEvent can be handled in Workers functions written using the ES modules format by adding an email function to your module’s exported handlers:

export default {
async email(message, env, ctx) {
message.forward("<YOUR_EMAIL>");
},
};
EmailEvent can be handled in Workers functions written using the ES modules format by adding an email function to your module’s exported handlers:

export default {
async email(message, env, ctx) {
message.forward("<YOUR_EMAIL>");
},
};
Dovid G
Dovid G7mo ago
Cloudflare Docs
Runtime API · Cloudflare Email Routing docs
An EmailEvent is the event type to programmatically process your emails with a Worker. You can reject, forward, or drop emails according to the logic …
Dovid G
Dovid G7mo ago
Sounds like any Worker can handle emails by adding this parameter
Hello, I’m Allie!
Yeah, you can write it in the Worker, but you can't configure which emails are routed to that Worker If that is what you mean
Dovid G
Dovid G7mo ago
What makes you say it cant be configured for routing?
Hello, I’m Allie!
Deciding which addresses are handled by a given Worker can only be done in the dashboard
Dovid G
Dovid G7mo ago
Why else would you handle EmailEvent?
Hello, I’m Allie!
I mean that you can write code to handle incoming emails in a Worker, but to actually use that code, you need to connect some addresses to the Worker via the dash
Dovid G
Dovid G7mo ago
Ok, thanks I am trying to implement the Email Docs example for sending email Any idea where there are docs for the package example is using? import { EmailMessage } from 'cloudflare:email'
Hello, I’m Allie!
npm
@cloudflare/workers-types
TypeScript typings for Cloudflare Workers. Latest version: 4.20240208.0, last published: 8 days ago. Start using @cloudflare/workers-types in your project by running npm i @cloudflare/workers-types. There are 113 other projects in the npm registry using @cloudflare/workers-types.
Dovid G
Dovid G7mo ago
Thanks, your saying there is no documentation only types? Getting error locally: service core:user:driving-theory: Uncaught Error: No such module "cloudflare-internal:email Presumably the local dev server does not yet support email?
Want results from more Discord servers?
Add your server