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 G10mo ago
How do I configure the worker locally in Wrangler to indicate to Cloudflare that its a Email Worker?
Hello, I’m Allie!
Hello, I’m Allie!OP10mo ago
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 G10mo 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!
Hello, I’m Allie!OP10mo ago
It doesn't look like it The config parser only shows options for send_email
Dovid G
Dovid G10mo 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 G10mo 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 G10mo ago
Sounds like any Worker can handle emails by adding this parameter
Hello, I’m Allie!
Hello, I’m Allie!OP10mo ago
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 G10mo ago
What makes you say it cant be configured for routing?
Hello, I’m Allie!
Hello, I’m Allie!OP10mo ago
Deciding which addresses are handled by a given Worker can only be done in the dashboard
Dovid G
Dovid G10mo ago
Why else would you handle EmailEvent?
Hello, I’m Allie!
Hello, I’m Allie!OP10mo ago
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 G10mo 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!
Hello, I’m Allie!OP10mo ago
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 G10mo 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?
Hello, I’m Allie!
Hello, I’m Allie!OP10mo ago
Is that at build, or at runtime?
Dovid G
Dovid G10mo ago
npm run dev from simple Workers template project
Hello, I’m Allie!
Hello, I’m Allie!OP10mo ago
No I mean when does the error occur when running dev
Dovid G
Dovid G10mo ago
It occurs on start/build Here is the full error:
✘ [ERROR] service core:user:driving-theory: Uncaught Error: No such module "cloudflare-internal:email".

imported from "cloudflare:email"


✘ [ERROR] MiniflareCoreError [ERR_RUNTIME_FAILURE]: The Workers runtime failed to start. There is likely additional logging output above.
✘ [ERROR] service core:user:driving-theory: Uncaught Error: No such module "cloudflare-internal:email".

imported from "cloudflare:email"


✘ [ERROR] MiniflareCoreError [ERR_RUNTIME_FAILURE]: The Workers runtime failed to start. There is likely additional logging output above.
Hello, I’m Allie!
Hello, I’m Allie!OP10mo ago
Yeah, gonna guess that it just doesn’t work locally
Dovid G
Dovid G10mo ago
I can confirm from docs that its not supported: https://github.com/cloudflare/workers-sdk/tree/main/packages/miniflare
Want results from more Discord servers?
Add your server