[Bad docs] TypeError when sending an email from a worker

Hi, I’m following the tutorial on how to send an email from a Worker https://developers.cloudflare.com/email-routing/email-workers/send-email-workers/.

Unfortunately the TOML provided does not work:

send_email = [
    {type = "send_email", name = "<NAME_FOR_BINDING>", destination_address = "<YOUR_EMAIL>@example.com"},
]

My TOML file looks like this:

name = "redacted"
main = "src/index.ts"
compatibility_date = "redacted"

[[kv_namespaces]]
binding = "redacted"
id = "redacted"

send_email = [
    {type = "send_email", name = "CF_MAILER"},
]

When I run my code, I get TypeError: Cannot read properties of undefined (reading 'send').

People more familiar with TOML will immediately see the issue, the send_mail table will end up inside kv_namespaces. You actually have to write :

name = "redacted"
main = "src/index.ts"
compatibility_date = "redacted"

[[kv_namespaces]]
binding = "redacted"
id = "redacted"

[[send_email]]
type = "send_email"
name = "CF_MAILER"

The docs really need to be updated with the [[send_email]] syntax. Currently they will trip up users.

A second issue happens when you run npm run dev in your workers project. It throws an error because of send_email :

⎔ Starting local server...
✘ [ERROR] service core:user:redacted: 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.

I’m running the latest [email protected]

1 Like