From 0d12b5a5e9f208ba97f67e6ad8335efcaec92238 Mon Sep 17 00:00:00 2001 From: Harshil Agrawal Date: Mon, 5 May 2025 13:29:49 +0200 Subject: [PATCH 1/3] update types and add note for service worker --- .../email-workers/runtime-api.mdx | 82 ++++++++++++------- 1 file changed, 54 insertions(+), 28 deletions(-) diff --git a/src/content/docs/email-routing/email-workers/runtime-api.mdx b/src/content/docs/email-routing/email-workers/runtime-api.mdx index 4b1c2114ac7b6fe..4b70718cd23d98d 100644 --- a/src/content/docs/email-routing/email-workers/runtime-api.mdx +++ b/src/content/docs/email-routing/email-workers/runtime-api.mdx @@ -10,28 +10,6 @@ sidebar: 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 you construct in your Worker. -*** - -## Syntax: Service Worker - -`EmailEvent` can be handled in Workers functions written using the Service Worker syntax by attaching to the `email` event with `addEventListener`: - -```js -addEventListener("email", async (event) => { - await event.message.forward(""); -}); -``` - -### Properties - - - -* `event.message` EmailMessage - - * An [`EmailMessage` object](#emailmessage-definition). - - - *** ## Syntax: ES modules @@ -50,9 +28,9 @@ export default { -* `message` EmailMessage +* `message` ForwardableEmailMessage - * An [`EmailMessage` object](#emailmessage-definition). + * An [`ForwardableEmailMessage` object](#forwardableemailmessage-definition). * `env` object @@ -65,10 +43,38 @@ export default { *** -## `EmailMessage` definition +## Syntax: Service Worker + +:::caution[Service Workers are deprecated] + +Service Workers are deprecated, but still supported. We recommend using [Module Workers](/workers/reference/migrate-to-module-workers/) instead. New features may not be supported for Service Workers. + +::: + +`EmailEvent` can be handled in Workers functions written using the Service Worker syntax by attaching to the `email` event with `addEventListener`: + +```js +addEventListener("email", async (event) => { + await event.message.forward(""); +}); +``` + +### Properties + + + +* `event.message` ForwardableEmailMessage + + * An [`ForwardableEmailMessage` object](#forwardableemailmessage-definition). + + + +*** + +## `ForwardableEmailMessage` definition ```ts - interface EmailMessage { + interface ForwardableEmailMessage { readonly from: string; readonly to: string; readonly headers: Headers; @@ -83,7 +89,7 @@ export default { } ``` - +An email message that is sent to a consumer Worker and can be rejected/forwarded. * `from` string @@ -114,7 +120,27 @@ export default { * Forward this email message to a verified destination address of the account. If you want, you can add extra headers to the email message. Only `X-*` headers are allowed. * When the promise resolves, the message is confirmed to be forwarded to a verified destination address. -* reply(messageEmailMessage) : Promise +* reply(EmailMessage) : Promise * Reply to the sender of this email message with a new EmailMessage object. * When the promise resolves, the message is confirmed to be replied. + + +## `EmailMessage` definition + +```ts +interface EmailMessage { + readonly from: string; + readonly to: string; +} +``` + +An email message that can be sent from a Worker. + +* `from` string + + * `Envelope From` attribute of the email message. + +* `to` string + + * `Envelope To` attribute of the email message. \ No newline at end of file From 4608a93b1669e325c1a80a178fd04282c26f9cbd Mon Sep 17 00:00:00 2001 From: ToriLindsay Date: Tue, 6 May 2025 10:35:34 +0100 Subject: [PATCH 2/3] Update src/content/docs/email-routing/email-workers/runtime-api.mdx --- src/content/docs/email-routing/email-workers/runtime-api.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/content/docs/email-routing/email-workers/runtime-api.mdx b/src/content/docs/email-routing/email-workers/runtime-api.mdx index 4b70718cd23d98d..cf6563d3c7cc6ea 100644 --- a/src/content/docs/email-routing/email-workers/runtime-api.mdx +++ b/src/content/docs/email-routing/email-workers/runtime-api.mdx @@ -30,7 +30,7 @@ export default { * `message` ForwardableEmailMessage - * An [`ForwardableEmailMessage` object](#forwardableemailmessage-definition). + * A [`ForwardableEmailMessage` object](#forwardableemailmessage-definition). * `env` object From f638f0bcd43e5f8b7777e62c9645dacf603b9bcb Mon Sep 17 00:00:00 2001 From: Kody Jackson Date: Tue, 6 May 2025 16:36:38 -0500 Subject: [PATCH 3/3] Retrigger CI --- src/content/docs/email-routing/email-workers/runtime-api.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/content/docs/email-routing/email-workers/runtime-api.mdx b/src/content/docs/email-routing/email-workers/runtime-api.mdx index cf6563d3c7cc6ea..65ef072a00e354d 100644 --- a/src/content/docs/email-routing/email-workers/runtime-api.mdx +++ b/src/content/docs/email-routing/email-workers/runtime-api.mdx @@ -47,7 +47,7 @@ export default { :::caution[Service Workers are deprecated] -Service Workers are deprecated, but still supported. We recommend using [Module Workers](/workers/reference/migrate-to-module-workers/) instead. New features may not be supported for Service Workers. +Service Workers are deprecated but still supported. We recommend using [Module Workers](/workers/reference/migrate-to-module-workers/) instead. New features may not be supported for Service Workers. :::