File
Blob: types/defines/email.d.ts
| 1 | /** |
| 2 | * The returned data after sending an email |
| 3 | */ |
| 4 | interface EmailSendResult { |
| 5 | /** |
| 6 | * The Email Message ID |
| 7 | */ |
| 8 | messageId: string; |
| 9 | } |
| 10 | |
| 11 | /** |
| 12 | * An email message that can be sent from a Worker. |
| 13 | */ |
| 14 | interface EmailMessage { |
| 15 | /** |
| 16 | * Envelope From attribute of the email message. |
| 17 | */ |
| 18 | readonly from: string; |
| 19 | /** |
| 20 | * Envelope To attribute of the email message. |
| 21 | */ |
| 22 | readonly to: string; |
| 23 | } |
| 24 | |
| 25 | /** |
| 26 | * An email message that is sent to a consumer Worker and can be rejected/forwarded. |
| 27 | */ |
| 28 | interface ForwardableEmailMessage extends EmailMessage { |
| 29 | /** |
| 30 | * Stream of the email message content. |
| 31 | */ |
| 32 | readonly raw: ReadableStream<Uint8Array>; |
| 33 | /** |
| 34 | * An [Headers object](https://developer.mozilla.org/en-US/docs/Web/API/Headers). |
| 35 | */ |
| 36 | readonly headers: Headers; |
| 37 | /** |
| 38 | * Size of the email message content. |
| 39 | */ |
| 40 | readonly rawSize: number; |
| 41 | /** |
| 42 | * Reject this email message by returning a permanent SMTP error back to the connecting client including the given reason. |
| 43 | * @param reason The reject reason. |
| 44 | * @returns void |
| 45 | */ |
| 46 | setReject(reason: string): void; |
| 47 | /** |
| 48 | * Forward this email message to a verified destination address of the account. |
| 49 | * @param rcptTo Verified destination address. |
| 50 | * @param headers A [Headers object](https://developer.mozilla.org/en-US/docs/Web/API/Headers). |
| 51 | * @returns A promise that resolves when the email message is forwarded. |
| 52 | */ |
| 53 | forward(rcptTo: string, headers?: Headers): Promise<EmailSendResult>; |
| 54 | /** |
| 55 | * Reply to the sender of this email message with a new EmailMessage object. |
| 56 | * @param message The reply message. |
| 57 | * @returns A promise that resolves when the email message is replied. |
| 58 | */ |
| 59 | reply(message: EmailMessage): Promise<EmailSendResult>; |
| 60 | } |
| 61 | |
| 62 | /** A file attachment for an email message */ |
| 63 | type EmailAttachment = |
| 64 | | { disposition: 'inline'; contentId: string; filename: string; type: string; content: string | ArrayBuffer | ArrayBufferView } |
| 65 | | { disposition: 'attachment'; contentId?: undefined; filename: string; type: string; content: string | ArrayBuffer | ArrayBufferView }; |
| 66 | |
| 67 | /** An Email Address */ |
| 68 | interface EmailAddress { |
| 69 | name: string; |
| 70 | email: string; |
| 71 | } |
| 72 | |
| 73 | /** |
| 74 | * A binding that allows a Worker to send email messages. |
| 75 | */ |
| 76 | interface SendEmail { |
| 77 | send(message: EmailMessage): Promise<EmailSendResult>; |
| 78 | send(builder: { |
| 79 | from: string | EmailAddress; |
| 80 | to: string | string[]; |
| 81 | subject: string; |
| 82 | replyTo?: string | EmailAddress; |
| 83 | cc?: string | string[]; |
| 84 | bcc?: string | string[]; |
| 85 | headers?: Record<string, string>; |
| 86 | text?: string; |
| 87 | html?: string; |
| 88 | attachments?: EmailAttachment[]; |
| 89 | }): Promise<EmailSendResult>; |
| 90 | } |
| 91 | |
| 92 | declare abstract class EmailEvent extends ExtendableEvent { |
| 93 | readonly message: ForwardableEmailMessage; |
| 94 | } |
| 95 | |
| 96 | declare type EmailExportedHandler<Env = unknown, Props = unknown> = ( |
| 97 | message: ForwardableEmailMessage, |
| 98 | env: Env, |
| 99 | ctx: ExecutionContext<Props> |
| 100 | ) => void | Promise<void>; |
| 101 | |
| 102 | declare module "cloudflare:email" { |
| 103 | let _EmailMessage: { |
| 104 | prototype: EmailMessage; |
| 105 | new (from: string, to: string, raw: ReadableStream | string): EmailMessage; |
| 106 | }; |
| 107 | export { _EmailMessage as EmailMessage }; |
| 108 | } |