Skip to content

Commit 0de20f6

Browse files
harshil1712ToriLindsaykodster28
authored andcommitted
[Email Worker] Update type (#22204)
* update types and add note for service worker * Update src/content/docs/email-routing/email-workers/runtime-api.mdx * Retrigger CI --------- Co-authored-by: ToriLindsay <[email protected]> Co-authored-by: Kody Jackson <[email protected]>
1 parent 3266f52 commit 0de20f6

File tree

1 file changed

+54
-28
lines changed

1 file changed

+54
-28
lines changed

src/content/docs/email-routing/email-workers/runtime-api.mdx

Lines changed: 54 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -10,28 +10,6 @@ sidebar:
1010

1111
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.
1212

13-
***
14-
15-
## Syntax: Service Worker
16-
17-
`EmailEvent` can be handled in Workers functions written using the Service Worker syntax by attaching to the `email` event with `addEventListener`:
18-
19-
```js
20-
addEventListener("email", async (event) => {
21-
await event.message.forward("<YOUR_EMAIL>");
22-
});
23-
```
24-
25-
### Properties
26-
27-
28-
29-
* `event.message` EmailMessage
30-
31-
* An [`EmailMessage` object](#emailmessage-definition).
32-
33-
34-
3513
***
3614

3715
## Syntax: ES modules
@@ -50,9 +28,9 @@ export default {
5028

5129

5230

53-
* `message` EmailMessage
31+
* `message` ForwardableEmailMessage
5432

55-
* An [`EmailMessage` object](#emailmessage-definition).
33+
* A [`ForwardableEmailMessage` object](#forwardableemailmessage-definition).
5634

5735
* `env` object
5836

@@ -65,10 +43,38 @@ export default {
6543

6644
***
6745

68-
## `EmailMessage` definition
46+
## Syntax: Service Worker
47+
48+
:::caution[Service Workers are deprecated]
49+
50+
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.
51+
52+
:::
53+
54+
`EmailEvent` can be handled in Workers functions written using the Service Worker syntax by attaching to the `email` event with `addEventListener`:
55+
56+
```js
57+
addEventListener("email", async (event) => {
58+
await event.message.forward("<YOUR_EMAIL>");
59+
});
60+
```
61+
62+
### Properties
63+
64+
65+
66+
* `event.message` ForwardableEmailMessage
67+
68+
* An [`ForwardableEmailMessage` object](#forwardableemailmessage-definition).
69+
70+
71+
72+
***
73+
74+
## `ForwardableEmailMessage` definition
6975

7076
```ts
71-
interface EmailMessage<Body = unknown> {
77+
interface ForwardableEmailMessage<Body = unknown> {
7278
readonly from: string;
7379
readonly to: string;
7480
readonly headers: Headers;
@@ -83,7 +89,7 @@ export default {
8389
}
8490
```
8591

86-
92+
An email message that is sent to a consumer Worker and can be rejected/forwarded.
8793

8894
* `from` string
8995

@@ -114,7 +120,27 @@ export default {
114120
* 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.
115121
* When the promise resolves, the message is confirmed to be forwarded to a verified destination address.
116122

117-
* <code>reply(messageEmailMessage)</code> : Promise
123+
* <code>reply(EmailMessage)</code> : Promise
118124

119125
* Reply to the sender of this email message with a new EmailMessage object.
120126
* When the promise resolves, the message is confirmed to be replied.
127+
128+
129+
## `EmailMessage` definition
130+
131+
```ts
132+
interface EmailMessage {
133+
readonly from: string;
134+
readonly to: string;
135+
}
136+
```
137+
138+
An email message that can be sent from a Worker.
139+
140+
* `from` string
141+
142+
* `Envelope From` attribute of the email message.
143+
144+
* `to` string
145+
146+
* `Envelope To` attribute of the email message.

0 commit comments

Comments
 (0)