Trigger your Repeat via emails!
The email event allows you to trigger a Repeat via emails and access the contents of the email such as the to/from addresses, subject & body.
Event
declare interface Email {
from: string;
to: string;
cc: string;
bcc: string;
reply_to: string;
subject: string;
bodies: Record<string, string>;
}
Properties
from
The email address that the email was sent from.
to
The email address that the email was sent to.
cc
Any email addresses that were cc’d on the email.
bcc
Any email addresses that were bcc’d on the email.
reply_to
The email address that the sender specified as a reply address.
subject
The subject of the email.
bodies
An set of key-value pairs where the key is the MIME type of the body, such as text/plain
or text/html
and the value is the content of that body.
Handler
export default {
async email(email: Repeat.Email, env: Repeat.Env) {
// ...
},
};
Parameters
email
The inbound email that triggered the Repeat.
env
The env
object represents the Repeat’s environment, such as variables, storage and metrics as well as the various webhook integrations for different platforms.
Returns
void
|response
Your webhook handler does not need to return a Response, but you may return one optionally if necessary.
Examples
Post a message in Discord when an email is received
This example requires that you have added the Discord inbound webhook URL as the DISCORD_WEBHOOK_URL
variable. For more information, refer to Discord’s documentation.
export default {
async email(email: Repeat.Email, env: Repeat.Env) {
const message = `Received ${email.subject} from ${email.from} at ${Date.now().toTimeString()}.`;
await env.webhooks.discord(env.variables.DISCORD_WEBHOOK_URL, message);
},
};
Last updated on November 19, 2022