Send emails from Workers
You can send an email about your Worker's activity from your Worker to an email address verified on Email Routing. This is useful for when you want to know about certain types of events being triggered, for example.
Before you can bind an email address to your Worker, you need to enable Email Routing and have at least one verified email address. Then, create a new binding in the wrangler.toml file:
There are three types of bindings:
- No attribute defined: When you do not define an attribute, the binding has no restrictions in place. You can use it to send emails to any verified email address through Email Routing.
destination_address
: When you define thedestination_address
attribute, you create a targeted binding. This means you can only send emails to the chosen email address. For example,{type = "send_email", name = "<NAME_FOR_BINDING>", destination_address = "<YOUR_EMAIL>@example.com"}
.
For this particular binding, when you call thesend_email
function you can passnull
orundefined
to your Worker and it will assume the email address specified in the binding.allowed_destination_addresses
: When you specify this attribute, you create an allowlist, and can send emails to any email address on the list.
You can add one or more types of bindings to your wrangler.toml
file. However, each attribute must be on its own line:
Refer to the example below to learn how to construct a Worker capable of sending emails. This example uses MIMEText ↗: