From 3665761af19cf84bc03293538fa0c1376d6563da Mon Sep 17 00:00:00 2001 From: Guy Bedford Date: Fri, 8 May 2026 18:08:29 -0700 Subject: [PATCH 1/2] email: encapsulate bindings within worker::email --- Cargo.lock | 22 -- chompfile.toml | 2 +- publish.sh | 4 + test/src/send_email.rs | 5 +- worker-sys/src/types/email.rs | 521 ++++++++++++++++++++++++++++++++ worker/src/bindings/email.rs | 523 ++++++++++++++++++++++++++++++++ worker/src/bindings/mod.rs | 1 + worker/src/email.rs | 543 ++-------------------------------- worker/src/env.rs | 2 +- worker/src/lib.rs | 32 +- worker/src/send_email.rs | 47 --- 11 files changed, 1096 insertions(+), 606 deletions(-) create mode 100755 publish.sh create mode 100644 worker-sys/src/types/email.rs create mode 100644 worker/src/bindings/email.rs create mode 100644 worker/src/bindings/mod.rs delete mode 100644 worker/src/send_email.rs diff --git a/Cargo.lock b/Cargo.lock index b56361f50..a2ffa35fa 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1433,8 +1433,6 @@ dependencies = [ [[package]] name = "js-sys" version = "0.3.98" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "67df7112613f8bfd9150013a0314e196f4800d3201ae742489d999db2f979f08" dependencies = [ "cfg-if", "futures-util", @@ -3416,8 +3414,6 @@ dependencies = [ [[package]] name = "wasm-bindgen" version = "0.2.121" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49ace1d07c165b0864824eee619580c4689389afa9dc9ed3a4c75040d82e6790" dependencies = [ "cfg-if", "once_cell", @@ -3429,8 +3425,6 @@ dependencies = [ [[package]] name = "wasm-bindgen-cli-support" version = "0.2.121" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ea29d9c1f708939aba5ec705f9435af5d5e8ffbaeedff0561b8c9216780e3b5" dependencies = [ "anyhow", "base64", @@ -3447,8 +3441,6 @@ dependencies = [ [[package]] name = "wasm-bindgen-futures" version = "0.4.71" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96492d0d3ffba25305a7dc88720d250b1401d7edca02cc3bcd50633b424673b8" dependencies = [ "js-sys", "wasm-bindgen", @@ -3457,8 +3449,6 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" version = "0.2.121" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e68e6f4afd367a562002c05637acb8578ff2dea1943df76afb9e83d177c8578" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -3467,8 +3457,6 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" version = "0.2.121" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d95a9ec35c64b2a7cb35d3fead40c4238d0940c86d107136999567a4703259f2" dependencies = [ "bumpalo", "proc-macro2", @@ -3480,8 +3468,6 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" version = "0.2.121" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4e0100b01e9f0d03189a92b96772a1fb998639d981193d7dbab487302513441" dependencies = [ "unicode-ident", ] @@ -3489,8 +3475,6 @@ dependencies = [ [[package]] name = "wasm-bindgen-test" version = "0.3.71" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af5ec93229ad9ccd0a545a516dec76dc276613f278f6a91aa6b463d5b33d42d0" dependencies = [ "async-trait", "cast", @@ -3511,8 +3495,6 @@ dependencies = [ [[package]] name = "wasm-bindgen-test-macro" version = "0.3.71" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c81b9fef827e575e0e54431736d1baa0d700315d8c62cfef1f61fa3aad0cbeb" dependencies = [ "proc-macro2", "quote", @@ -3522,8 +3504,6 @@ dependencies = [ [[package]] name = "wasm-bindgen-test-shared" version = "0.2.121" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4f4d8ae7ad5440360e9799dfd42857d126454a88441ddf72d288ef83fa47f527" [[package]] name = "wasm-encoder" @@ -3609,8 +3589,6 @@ dependencies = [ [[package]] name = "web-sys" version = "0.3.98" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4b572dff8bcf38bad0fa19729c89bb5748b2b9b1d8be70cf90df697e3a8f32aa" dependencies = [ "js-sys", "wasm-bindgen", diff --git a/chompfile.toml b/chompfile.toml index 837a686ae..39eb2c54a 100644 --- a/chompfile.toml +++ b/chompfile.toml @@ -6,7 +6,7 @@ deps = ['install:ts-gen'] # `Env` / `ExecutionContext` are project-specific re-exports that ts-gen # can't infer; everything else (`ReadableStream`, `Headers`, `Event`, …) # resolves through ts-gen's built-in web_sys defaults. -run = '''ts-gen --input types/email.d.ts --output worker/src/email.rs \ +run = '''ts-gen --input types/email.d.ts --output worker/src/bindings/email.rs \ --errors-as-error \ --external "Env=crate::Env" \ --external "ExecutionContext=crate::Context"''' diff --git a/publish.sh b/publish.sh new file mode 100755 index 000000000..80a159b0b --- /dev/null +++ b/publish.sh @@ -0,0 +1,4 @@ +cargo publish -p worker-sys +cargo publish -p worker-macros +cargo publish -p worker +cargo publish -p worker-build diff --git a/test/src/send_email.rs b/test/src/send_email.rs index acc087ac4..f288be785 100644 --- a/test/src/send_email.rs +++ b/test/src/send_email.rs @@ -1,8 +1,9 @@ use crate::SomeSharedData; use futures_util::stream::once; use worker::{ - js_sys::Uint8Array, worker_sys, Date, EmailAddress, EmailAttachment, EmailMessage, Env, - FixedLengthStream, Request, Response, Result, SendEmail, SendEmailBuilder, + email::{EmailAddress, EmailAttachment, EmailMessage, SendEmail, SendEmailBuilder}, + js_sys::Uint8Array, + worker_sys, Date, Env, FixedLengthStream, Request, Response, Result, }; const SENDER: &str = "allowed-sender@example.com"; diff --git a/worker-sys/src/types/email.rs b/worker-sys/src/types/email.rs new file mode 100644 index 000000000..504ec633e --- /dev/null +++ b/worker-sys/src/types/email.rs @@ -0,0 +1,521 @@ +// Generated by ts-gen. Do not edit. + +#[allow(dead_code)] +use ::web_sys::Event; +#[allow(dead_code)] +use ::web_sys::Headers; +#[allow(dead_code)] +use ::web_sys::ReadableStream; +#[allow(unused_imports)] +use js_sys::*; +#[allow(unused_imports)] +use wasm_bindgen::prelude::*; +#[wasm_bindgen] +extern "C" { + # [wasm_bindgen (extends = Event , extends = Object)] + #[derive(Debug, Clone, PartialEq, Eq)] + pub type ExtendableEvent; + #[doc = " The **`ExtendableEvent.waitUntil()`** method tells the event dispatcher that work is ongoing."] + #[doc = ""] + #[doc = " [MDN Reference](https://developer.mozilla.org/docs/Web/API/ExtendableEvent/waitUntil)"] + #[wasm_bindgen(method, js_name = "waitUntil")] + pub fn wait_until(this: &ExtendableEvent, promise: &Promise); +} +#[wasm_bindgen] +extern "C" { + # [wasm_bindgen (extends = Object)] + #[derive(Debug, Clone, PartialEq, Eq)] + pub type EmailSendResult; + #[doc = " The Email Message ID"] + #[wasm_bindgen(method, getter, js_name = "messageId")] + pub fn message_id(this: &EmailSendResult) -> String; + #[wasm_bindgen(method, setter, js_name = "messageId")] + pub fn set_message_id(this: &EmailSendResult, val: &str); +} +impl EmailSendResult { + #[doc = " * `message_id` - The Email Message ID"] + pub fn new(message_id: &str) -> EmailSendResult { + let inner: Self = JsCast::unchecked_into(js_sys::Object::new()); + inner.set_message_id(message_id); + inner + } +} +#[wasm_bindgen] +extern "C" { + # [wasm_bindgen (extends = email :: EmailMessage , extends = Object)] + #[derive(Debug, Clone, PartialEq, Eq)] + pub type ForwardableEmailMessage; + #[doc = " Stream of the email message content."] + #[wasm_bindgen(method, getter)] + pub fn raw(this: &ForwardableEmailMessage) -> ReadableStream; + #[doc = " An [Headers object](https://developer.mozilla.org/en-US/docs/Web/API/Headers)."] + #[wasm_bindgen(method, getter)] + pub fn headers(this: &ForwardableEmailMessage) -> Headers; + #[doc = " Size of the email message content."] + #[wasm_bindgen(method, getter, js_name = "rawSize")] + pub fn raw_size(this: &ForwardableEmailMessage) -> f64; + #[doc = " Reject this email message by returning a permanent SMTP error back to the connecting client including the given reason."] + #[doc = ""] + #[doc = " * `reason` - The reject reason."] + #[doc = ""] + #[doc = " Returns: void"] + #[wasm_bindgen(method, js_name = "setReject")] + pub fn set_reject(this: &ForwardableEmailMessage, reason: &str); + #[doc = " Forward this email message to a verified destination address of the account."] + #[doc = ""] + #[doc = " * `rcptTo` - Verified destination address."] + #[doc = " * `headers` - A [Headers object](https://developer.mozilla.org/en-US/docs/Web/API/Headers)."] + #[doc = ""] + #[doc = " Returns: A promise that resolves when the email message is forwarded."] + #[wasm_bindgen(method, catch)] + pub async fn forward( + this: &ForwardableEmailMessage, + rcpt_to: &str, + ) -> Result; + #[doc = " Forward this email message to a verified destination address of the account."] + #[doc = ""] + #[doc = " * `rcptTo` - Verified destination address."] + #[doc = " * `headers` - A [Headers object](https://developer.mozilla.org/en-US/docs/Web/API/Headers)."] + #[doc = ""] + #[doc = " Returns: A promise that resolves when the email message is forwarded."] + #[wasm_bindgen(method, catch, js_name = "forward")] + pub async fn forward_with_headers( + this: &ForwardableEmailMessage, + rcpt_to: &str, + headers: &Headers, + ) -> Result; + #[doc = " Reply to the sender of this email message with a new EmailMessage object."] + #[doc = ""] + #[doc = " * `message` - The reply message."] + #[doc = ""] + #[doc = " Returns: A promise that resolves when the email message is replied."] + #[wasm_bindgen(method, catch)] + pub async fn reply( + this: &ForwardableEmailMessage, + message: &email::EmailMessage, + ) -> Result; +} +#[wasm_bindgen] +extern "C" { + # [wasm_bindgen (extends = Object)] + #[derive(Debug, Clone, PartialEq, Eq)] + pub type EmailAttachment; + #[wasm_bindgen(method, getter)] + pub fn disposition(this: &EmailAttachment) -> DispositionKind; + #[wasm_bindgen(method, setter)] + pub fn set_disposition(this: &EmailAttachment, val: &str); + #[wasm_bindgen(method, getter, js_name = "contentId")] + pub fn content_id(this: &EmailAttachment) -> Option; + #[wasm_bindgen(method, setter, js_name = "contentId")] + pub fn set_content_id(this: &EmailAttachment, val: &str); + #[wasm_bindgen(method, getter)] + pub fn filename(this: &EmailAttachment) -> String; + #[wasm_bindgen(method, setter)] + pub fn set_filename(this: &EmailAttachment, val: &str); + #[wasm_bindgen(method, getter, js_name = "type")] + pub fn type_(this: &EmailAttachment) -> String; + #[wasm_bindgen(method, setter)] + pub fn set_type(this: &EmailAttachment, val: &str); + #[wasm_bindgen(method, getter)] + pub fn content(this: &EmailAttachment) -> ContentKind; + #[wasm_bindgen(method, setter)] + pub fn set_content(this: &EmailAttachment, val: &str); + #[wasm_bindgen(method, setter, js_name = "content")] + pub fn set_content_with_array_buffer(this: &EmailAttachment, val: &ArrayBuffer); + #[wasm_bindgen(method, setter, js_name = "content")] + pub fn set_content_with_typed_array(this: &EmailAttachment, val: &T); +} +impl EmailAttachment { + #[doc = " ## Inlined fields"] + #[doc = ""] + #[doc = " * `disposition: \"inline\"`"] + pub fn new_inline( + content_id: &str, + filename: &str, + r#type: &str, + content: &str, + ) -> EmailAttachment { + let inner: Self = JsCast::unchecked_into(js_sys::Object::new()); + inner.set_disposition("inline"); + inner.set_content_id(content_id); + inner.set_filename(filename); + inner.set_type(r#type); + inner.set_content(content); + inner + } + #[doc = " ## Inlined fields"] + #[doc = ""] + #[doc = " * `disposition: \"inline\"`"] + pub fn new_inline_with_array_buffer( + content_id: &str, + filename: &str, + r#type: &str, + content: &ArrayBuffer, + ) -> EmailAttachment { + let inner: Self = JsCast::unchecked_into(js_sys::Object::new()); + inner.set_disposition("inline"); + inner.set_content_id(content_id); + inner.set_filename(filename); + inner.set_type(r#type); + inner.set_content_with_array_buffer(content); + inner + } + #[doc = " ## Inlined fields"] + #[doc = ""] + #[doc = " * `disposition: \"inline\"`"] + pub fn new_inline_with_typed_array( + content_id: &str, + filename: &str, + r#type: &str, + content: &T, + ) -> EmailAttachment { + let inner: Self = JsCast::unchecked_into(js_sys::Object::new()); + inner.set_disposition("inline"); + inner.set_content_id(content_id); + inner.set_filename(filename); + inner.set_type(r#type); + inner.set_content_with_typed_array(content); + inner + } + #[doc = " ## Inlined fields"] + #[doc = ""] + #[doc = " * `disposition: \"attachment\"`"] + pub fn new_attachment(filename: &str, r#type: &str, content: &str) -> EmailAttachment { + Self::builder_attachment(filename, r#type, content).build() + } + #[doc = " ## Inlined fields"] + #[doc = ""] + #[doc = " * `disposition: \"attachment\"`"] + pub fn new_attachment_with_array_buffer( + filename: &str, + r#type: &str, + content: &ArrayBuffer, + ) -> EmailAttachment { + Self::builder_attachment_with_array_buffer(filename, r#type, content).build() + } + #[doc = " ## Inlined fields"] + #[doc = ""] + #[doc = " * `disposition: \"attachment\"`"] + pub fn new_attachment_with_typed_array( + filename: &str, + r#type: &str, + content: &T, + ) -> EmailAttachment { + Self::builder_attachment_with_typed_array(filename, r#type, content).build() + } + #[doc = " ## Inlined fields"] + #[doc = ""] + #[doc = " * `disposition: \"attachment\"`"] + pub fn builder_attachment( + filename: &str, + r#type: &str, + content: &str, + ) -> EmailAttachmentBuilder { + let inner: Self = JsCast::unchecked_into(js_sys::Object::new()); + inner.set_disposition("attachment"); + inner.set_filename(filename); + inner.set_type(r#type); + inner.set_content(content); + EmailAttachmentBuilder { inner } + } + #[doc = " ## Inlined fields"] + #[doc = ""] + #[doc = " * `disposition: \"attachment\"`"] + pub fn builder_attachment_with_array_buffer( + filename: &str, + r#type: &str, + content: &ArrayBuffer, + ) -> EmailAttachmentBuilder { + let inner: Self = JsCast::unchecked_into(js_sys::Object::new()); + inner.set_disposition("attachment"); + inner.set_filename(filename); + inner.set_type(r#type); + inner.set_content_with_array_buffer(content); + EmailAttachmentBuilder { inner } + } + #[doc = " ## Inlined fields"] + #[doc = ""] + #[doc = " * `disposition: \"attachment\"`"] + pub fn builder_attachment_with_typed_array( + filename: &str, + r#type: &str, + content: &T, + ) -> EmailAttachmentBuilder { + let inner: Self = JsCast::unchecked_into(js_sys::Object::new()); + inner.set_disposition("attachment"); + inner.set_filename(filename); + inner.set_type(r#type); + inner.set_content_with_typed_array(content); + EmailAttachmentBuilder { inner } + } +} +pub struct EmailAttachmentBuilder { + inner: EmailAttachment, +} +impl EmailAttachmentBuilder { + pub fn content_id(self, val: &str) -> Self { + self.inner.set_content_id(val); + self + } + pub fn build(self) -> EmailAttachment { + self.inner + } +} +#[wasm_bindgen] +extern "C" { + # [wasm_bindgen (extends = Object)] + #[derive(Debug, Clone, PartialEq, Eq)] + pub type EmailAddress; + #[wasm_bindgen(method, getter)] + pub fn name(this: &EmailAddress) -> String; + #[wasm_bindgen(method, setter)] + pub fn set_name(this: &EmailAddress, val: &str); + #[wasm_bindgen(method, getter)] + pub fn email(this: &EmailAddress) -> String; + #[wasm_bindgen(method, setter)] + pub fn set_email(this: &EmailAddress, val: &str); +} +impl EmailAddress { + pub fn new(name: &str, email: &str) -> EmailAddress { + let inner: Self = JsCast::unchecked_into(js_sys::Object::new()); + inner.set_name(name); + inner.set_email(email); + inner + } +} +#[wasm_bindgen] +extern "C" { + # [wasm_bindgen (extends = Object)] + #[derive(Debug, Clone, PartialEq, Eq)] + pub type SendEmail; + #[wasm_bindgen(method, catch)] + pub async fn send( + this: &SendEmail, + message: &email::EmailMessage, + ) -> Result; + #[wasm_bindgen(method, catch, js_name = "send")] + pub async fn send_with_builder( + this: &SendEmail, + builder: &SendEmailBuilder, + ) -> Result; +} +#[wasm_bindgen] +extern "C" { + # [wasm_bindgen (extends = Object)] + #[derive(Debug, Clone, PartialEq, Eq)] + pub type SendEmailBuilder; + #[wasm_bindgen(method, getter)] + pub fn from(this: &SendEmailBuilder) -> FromKind; + #[wasm_bindgen(method, setter)] + pub fn set_from(this: &SendEmailBuilder, val: &str); + #[wasm_bindgen(method, setter, js_name = "from")] + pub fn set_from_with_email_address(this: &SendEmailBuilder, val: &EmailAddress); + #[wasm_bindgen(method, getter)] + pub fn to(this: &SendEmailBuilder) -> ToKind; + #[wasm_bindgen(method, setter)] + pub fn set_to(this: &SendEmailBuilder, val: &str); + #[wasm_bindgen(method, setter, slice_to_array, js_name = "to")] + pub fn set_to_with_slice(this: &SendEmailBuilder, val: &[String]); + #[wasm_bindgen(method, getter)] + pub fn subject(this: &SendEmailBuilder) -> String; + #[wasm_bindgen(method, setter)] + pub fn set_subject(this: &SendEmailBuilder, val: &str); + #[wasm_bindgen(method, getter, js_name = "replyTo")] + pub fn reply_to(this: &SendEmailBuilder) -> Option; + #[wasm_bindgen(method, setter, js_name = "replyTo")] + pub fn set_reply_to(this: &SendEmailBuilder, val: &str); + #[wasm_bindgen(method, setter, js_name = "replyTo")] + pub fn set_reply_to_with_email_address(this: &SendEmailBuilder, val: &EmailAddress); + #[wasm_bindgen(method, getter)] + pub fn cc(this: &SendEmailBuilder) -> Option; + #[wasm_bindgen(method, setter)] + pub fn set_cc(this: &SendEmailBuilder, val: &str); + #[wasm_bindgen(method, setter, slice_to_array, js_name = "cc")] + pub fn set_cc_with_slice(this: &SendEmailBuilder, val: &[String]); + #[wasm_bindgen(method, getter)] + pub fn bcc(this: &SendEmailBuilder) -> Option; + #[wasm_bindgen(method, setter)] + pub fn set_bcc(this: &SendEmailBuilder, val: &str); + #[wasm_bindgen(method, setter, slice_to_array, js_name = "bcc")] + pub fn set_bcc_with_slice(this: &SendEmailBuilder, val: &[String]); + #[wasm_bindgen(method, getter)] + pub fn headers(this: &SendEmailBuilder) -> Option>; + #[wasm_bindgen(method, setter)] + pub fn set_headers(this: &SendEmailBuilder, val: &Object); + #[wasm_bindgen(method, getter)] + pub fn text(this: &SendEmailBuilder) -> Option; + #[wasm_bindgen(method, setter)] + pub fn set_text(this: &SendEmailBuilder, val: &str); + #[wasm_bindgen(method, getter)] + pub fn html(this: &SendEmailBuilder) -> Option; + #[wasm_bindgen(method, setter)] + pub fn set_html(this: &SendEmailBuilder, val: &str); + #[wasm_bindgen(method, getter)] + pub fn attachments(this: &SendEmailBuilder) -> Option>; + #[wasm_bindgen(method, setter, slice_to_array)] + pub fn set_attachments(this: &SendEmailBuilder, val: &[EmailAttachment]); +} +impl SendEmailBuilder { + pub fn new(from: &str, to: &str, subject: &str) -> SendEmailBuilder { + Self::builder(from, to, subject).build() + } + pub fn new_with_str_and_slice(from: &str, to: &[String], subject: &str) -> SendEmailBuilder { + Self::builder_with_str_and_slice(from, to, subject).build() + } + pub fn new_with_email_address_and_str( + from: &EmailAddress, + to: &str, + subject: &str, + ) -> SendEmailBuilder { + Self::builder_with_email_address_and_str(from, to, subject).build() + } + pub fn new_with_email_address_and_slice( + from: &EmailAddress, + to: &[String], + subject: &str, + ) -> SendEmailBuilder { + Self::builder_with_email_address_and_slice(from, to, subject).build() + } + pub fn builder(from: &str, to: &str, subject: &str) -> SendEmailBuilderBuilder { + let inner: Self = JsCast::unchecked_into(js_sys::Object::new()); + inner.set_from(from); + inner.set_to(to); + inner.set_subject(subject); + SendEmailBuilderBuilder { inner } + } + pub fn builder_with_str_and_slice( + from: &str, + to: &[String], + subject: &str, + ) -> SendEmailBuilderBuilder { + let inner: Self = JsCast::unchecked_into(js_sys::Object::new()); + inner.set_from(from); + inner.set_to_with_slice(to); + inner.set_subject(subject); + SendEmailBuilderBuilder { inner } + } + pub fn builder_with_email_address_and_str( + from: &EmailAddress, + to: &str, + subject: &str, + ) -> SendEmailBuilderBuilder { + let inner: Self = JsCast::unchecked_into(js_sys::Object::new()); + inner.set_from_with_email_address(from); + inner.set_to(to); + inner.set_subject(subject); + SendEmailBuilderBuilder { inner } + } + pub fn builder_with_email_address_and_slice( + from: &EmailAddress, + to: &[String], + subject: &str, + ) -> SendEmailBuilderBuilder { + let inner: Self = JsCast::unchecked_into(js_sys::Object::new()); + inner.set_from_with_email_address(from); + inner.set_to_with_slice(to); + inner.set_subject(subject); + SendEmailBuilderBuilder { inner } + } +} +pub struct SendEmailBuilderBuilder { + inner: SendEmailBuilder, +} +impl SendEmailBuilderBuilder { + pub fn reply_to(self, val: &str) -> Self { + self.inner.set_reply_to(val); + self + } + pub fn reply_to_with_email_address(self, val: &EmailAddress) -> Self { + self.inner.set_reply_to_with_email_address(val); + self + } + pub fn cc(self, val: &str) -> Self { + self.inner.set_cc(val); + self + } + pub fn cc_with_slice(self, val: &[String]) -> Self { + self.inner.set_cc_with_slice(val); + self + } + pub fn bcc(self, val: &str) -> Self { + self.inner.set_bcc(val); + self + } + pub fn bcc_with_slice(self, val: &[String]) -> Self { + self.inner.set_bcc_with_slice(val); + self + } + pub fn headers(self, val: &Object) -> Self { + self.inner.set_headers(val); + self + } + pub fn text(self, val: &str) -> Self { + self.inner.set_text(val); + self + } + pub fn html(self, val: &str) -> Self { + self.inner.set_html(val); + self + } + pub fn attachments(self, val: &[EmailAttachment]) -> Self { + self.inner.set_attachments(val); + self + } + pub fn build(self) -> SendEmailBuilder { + self.inner + } +} +#[wasm_bindgen] +extern "C" { + # [wasm_bindgen (extends = ExtendableEvent , extends = Object)] + #[derive(Debug, Clone, PartialEq, Eq)] + pub type EmailEvent; + #[wasm_bindgen(method, getter)] + pub fn message(this: &EmailEvent) -> ForwardableEmailMessage; +} +pub mod email { + use super::*; + use js_sys::*; + use wasm_bindgen::prelude::*; + #[wasm_bindgen(module = "cloudflare:email")] + extern "C" { + # [wasm_bindgen (extends = Object)] + #[derive(Debug, Clone, PartialEq, Eq)] + pub type EmailMessage; + #[wasm_bindgen(constructor, catch)] + pub fn new(from: &str, to: &str, raw: &str) -> Result; + #[wasm_bindgen(constructor, catch, js_name = "EmailMessage")] + pub fn new_with_readable_stream( + from: &str, + to: &str, + raw: &ReadableStream, + ) -> Result; + #[doc = " Envelope From attribute of the email message."] + #[wasm_bindgen(method, getter)] + pub fn from(this: &EmailMessage) -> String; + #[doc = " Envelope To attribute of the email message."] + #[wasm_bindgen(method, getter)] + pub fn to(this: &EmailMessage) -> String; + } +} +#[wasm_bindgen] +pub enum DispositionKind { + Inline = "inline", + Attachment = "attachment", +} +#[wasm_bindgen] +pub enum ContentKind { + String(String), + ArrayBuffer(ArrayBuffer), + Uint8Array(Uint8Array), +} +#[wasm_bindgen] +pub enum FromKind { + String(String), + EmailAddress(EmailAddress), +} +#[wasm_bindgen] +pub enum ToKind { + String(String), + VecOfString(Vec), +} diff --git a/worker/src/bindings/email.rs b/worker/src/bindings/email.rs new file mode 100644 index 000000000..8ed7d0ba7 --- /dev/null +++ b/worker/src/bindings/email.rs @@ -0,0 +1,523 @@ +// Generated by ts-gen. Do not edit. + +#[allow(dead_code)] +use ::web_sys::Event; +#[allow(dead_code)] +use ::web_sys::Headers; +#[allow(dead_code)] +use ::web_sys::ReadableStream; +#[allow(unused_imports)] +use js_sys::*; +#[allow(unused_imports)] +use wasm_bindgen::prelude::*; +#[wasm_bindgen] +extern "C" { + # [wasm_bindgen (extends = Event , extends = Object)] + #[derive(Debug, Clone, PartialEq, Eq)] + pub type ExtendableEvent; + #[doc = " The **`ExtendableEvent.waitUntil()`** method tells the event dispatcher that work is ongoing."] + #[doc = ""] + #[doc = " [MDN Reference](https://developer.mozilla.org/docs/Web/API/ExtendableEvent/waitUntil)"] + #[wasm_bindgen(method, js_name = "waitUntil")] + pub fn wait_until(this: &ExtendableEvent, promise: &Promise); +} +#[wasm_bindgen] +extern "C" { + # [wasm_bindgen (extends = Object)] + #[derive(Debug, Clone, PartialEq, Eq)] + pub type EmailSendResult; + #[doc = " The Email Message ID"] + #[wasm_bindgen(method, getter, js_name = "messageId")] + pub fn message_id(this: &EmailSendResult) -> String; + #[wasm_bindgen(method, setter, js_name = "messageId")] + pub fn set_message_id(this: &EmailSendResult, val: &str); +} +impl EmailSendResult { + #[doc = " * `message_id` - The Email Message ID"] + pub fn new(message_id: &str) -> EmailSendResult { + let inner: Self = JsCast::unchecked_into(js_sys::Object::new()); + inner.set_message_id(message_id); + inner + } +} +#[wasm_bindgen] +extern "C" { + # [wasm_bindgen (extends = email :: EmailMessage , extends = Object)] + #[derive(Debug, Clone, PartialEq, Eq)] + pub type ForwardableEmailMessage; + #[doc = " Stream of the email message content."] + #[wasm_bindgen(method, getter)] + pub fn raw(this: &ForwardableEmailMessage) -> ReadableStream; + #[doc = " An [Headers object](https://developer.mozilla.org/en-US/docs/Web/API/Headers)."] + #[wasm_bindgen(method, getter)] + pub fn headers(this: &ForwardableEmailMessage) -> Headers; + #[doc = " Size of the email message content."] + #[wasm_bindgen(method, getter, js_name = "rawSize")] + pub fn raw_size(this: &ForwardableEmailMessage) -> f64; + #[doc = " Reject this email message by returning a permanent SMTP error back to the connecting client including the given reason."] + #[doc = ""] + #[doc = " * `reason` - The reject reason."] + #[doc = ""] + #[doc = " Returns: void"] + #[wasm_bindgen(method, js_name = "setReject")] + pub fn set_reject(this: &ForwardableEmailMessage, reason: &str); + #[doc = " Forward this email message to a verified destination address of the account."] + #[doc = ""] + #[doc = " * `rcptTo` - Verified destination address."] + #[doc = " * `headers` - A [Headers object](https://developer.mozilla.org/en-US/docs/Web/API/Headers)."] + #[doc = ""] + #[doc = " Returns: A promise that resolves when the email message is forwarded."] + #[wasm_bindgen(method, catch)] + pub async fn forward( + this: &ForwardableEmailMessage, + rcpt_to: &str, + ) -> Result; + #[doc = " Forward this email message to a verified destination address of the account."] + #[doc = ""] + #[doc = " * `rcptTo` - Verified destination address."] + #[doc = " * `headers` - A [Headers object](https://developer.mozilla.org/en-US/docs/Web/API/Headers)."] + #[doc = ""] + #[doc = " Returns: A promise that resolves when the email message is forwarded."] + #[wasm_bindgen(method, catch, js_name = "forward")] + pub async fn forward_with_headers( + this: &ForwardableEmailMessage, + rcpt_to: &str, + headers: &Headers, + ) -> Result; + #[doc = " Reply to the sender of this email message with a new EmailMessage object."] + #[doc = ""] + #[doc = " * `message` - The reply message."] + #[doc = ""] + #[doc = " Returns: A promise that resolves when the email message is replied."] + #[wasm_bindgen(method, catch)] + pub async fn reply( + this: &ForwardableEmailMessage, + message: &email::EmailMessage, + ) -> Result; +} +#[wasm_bindgen] +extern "C" { + # [wasm_bindgen (extends = Object)] + #[derive(Debug, Clone, PartialEq, Eq)] + pub type EmailAttachment; + #[wasm_bindgen(method, getter)] + pub fn disposition(this: &EmailAttachment) -> DispositionKind; + #[wasm_bindgen(method, setter)] + pub fn set_disposition(this: &EmailAttachment, val: &str); + #[wasm_bindgen(method, getter, js_name = "contentId")] + pub fn content_id(this: &EmailAttachment) -> Option; + #[wasm_bindgen(method, setter, js_name = "contentId")] + pub fn set_content_id(this: &EmailAttachment, val: &str); + #[wasm_bindgen(method, getter)] + pub fn filename(this: &EmailAttachment) -> String; + #[wasm_bindgen(method, setter)] + pub fn set_filename(this: &EmailAttachment, val: &str); + #[wasm_bindgen(method, getter, js_name = "type")] + pub fn type_(this: &EmailAttachment) -> String; + #[wasm_bindgen(method, setter)] + pub fn set_type(this: &EmailAttachment, val: &str); + #[wasm_bindgen(method, getter)] + pub fn content(this: &EmailAttachment) -> ContentKind; + #[wasm_bindgen(method, setter)] + pub fn set_content(this: &EmailAttachment, val: &str); + #[wasm_bindgen(method, setter, js_name = "content")] + pub fn set_content_with_array_buffer(this: &EmailAttachment, val: &ArrayBuffer); + #[wasm_bindgen(method, setter, js_name = "content")] + pub fn set_content_with_typed_array(this: &EmailAttachment, val: &T); +} +impl EmailAttachment { + #[doc = " ## Inlined fields"] + #[doc = ""] + #[doc = " * `disposition: \"inline\"`"] + pub fn new_inline( + content_id: &str, + filename: &str, + r#type: &str, + content: &str, + ) -> EmailAttachment { + let inner: Self = JsCast::unchecked_into(js_sys::Object::new()); + inner.set_disposition("inline"); + inner.set_content_id(content_id); + inner.set_filename(filename); + inner.set_type(r#type); + inner.set_content(content); + inner + } + #[doc = " ## Inlined fields"] + #[doc = ""] + #[doc = " * `disposition: \"inline\"`"] + pub fn new_inline_with_array_buffer( + content_id: &str, + filename: &str, + r#type: &str, + content: &ArrayBuffer, + ) -> EmailAttachment { + let inner: Self = JsCast::unchecked_into(js_sys::Object::new()); + inner.set_disposition("inline"); + inner.set_content_id(content_id); + inner.set_filename(filename); + inner.set_type(r#type); + inner.set_content_with_array_buffer(content); + inner + } + #[doc = " ## Inlined fields"] + #[doc = ""] + #[doc = " * `disposition: \"inline\"`"] + pub fn new_inline_with_typed_array( + content_id: &str, + filename: &str, + r#type: &str, + content: &T, + ) -> EmailAttachment { + let inner: Self = JsCast::unchecked_into(js_sys::Object::new()); + inner.set_disposition("inline"); + inner.set_content_id(content_id); + inner.set_filename(filename); + inner.set_type(r#type); + inner.set_content_with_typed_array(content); + inner + } + #[doc = " ## Inlined fields"] + #[doc = ""] + #[doc = " * `disposition: \"attachment\"`"] + pub fn new_attachment(filename: &str, r#type: &str, content: &str) -> EmailAttachment { + Self::builder_attachment(filename, r#type, content).build() + } + #[doc = " ## Inlined fields"] + #[doc = ""] + #[doc = " * `disposition: \"attachment\"`"] + pub fn new_attachment_with_array_buffer( + filename: &str, + r#type: &str, + content: &ArrayBuffer, + ) -> EmailAttachment { + Self::builder_attachment_with_array_buffer(filename, r#type, content).build() + } + #[doc = " ## Inlined fields"] + #[doc = ""] + #[doc = " * `disposition: \"attachment\"`"] + pub fn new_attachment_with_typed_array( + filename: &str, + r#type: &str, + content: &T, + ) -> EmailAttachment { + Self::builder_attachment_with_typed_array(filename, r#type, content).build() + } + #[doc = " ## Inlined fields"] + #[doc = ""] + #[doc = " * `disposition: \"attachment\"`"] + pub fn builder_attachment( + filename: &str, + r#type: &str, + content: &str, + ) -> EmailAttachmentBuilder { + let inner: Self = JsCast::unchecked_into(js_sys::Object::new()); + inner.set_disposition("attachment"); + inner.set_filename(filename); + inner.set_type(r#type); + inner.set_content(content); + EmailAttachmentBuilder { inner } + } + #[doc = " ## Inlined fields"] + #[doc = ""] + #[doc = " * `disposition: \"attachment\"`"] + pub fn builder_attachment_with_array_buffer( + filename: &str, + r#type: &str, + content: &ArrayBuffer, + ) -> EmailAttachmentBuilder { + let inner: Self = JsCast::unchecked_into(js_sys::Object::new()); + inner.set_disposition("attachment"); + inner.set_filename(filename); + inner.set_type(r#type); + inner.set_content_with_array_buffer(content); + EmailAttachmentBuilder { inner } + } + #[doc = " ## Inlined fields"] + #[doc = ""] + #[doc = " * `disposition: \"attachment\"`"] + pub fn builder_attachment_with_typed_array( + filename: &str, + r#type: &str, + content: &T, + ) -> EmailAttachmentBuilder { + let inner: Self = JsCast::unchecked_into(js_sys::Object::new()); + inner.set_disposition("attachment"); + inner.set_filename(filename); + inner.set_type(r#type); + inner.set_content_with_typed_array(content); + EmailAttachmentBuilder { inner } + } +} +pub struct EmailAttachmentBuilder { + inner: EmailAttachment, +} +impl EmailAttachmentBuilder { + pub fn content_id(self, val: &str) -> Self { + self.inner.set_content_id(val); + self + } + pub fn build(self) -> EmailAttachment { + self.inner + } +} +#[wasm_bindgen] +extern "C" { + # [wasm_bindgen (extends = Object)] + #[derive(Debug, Clone, PartialEq, Eq)] + pub type EmailAddress; + #[wasm_bindgen(method, getter)] + pub fn name(this: &EmailAddress) -> String; + #[wasm_bindgen(method, setter)] + pub fn set_name(this: &EmailAddress, val: &str); + #[wasm_bindgen(method, getter)] + pub fn email(this: &EmailAddress) -> String; + #[wasm_bindgen(method, setter)] + pub fn set_email(this: &EmailAddress, val: &str); +} +impl EmailAddress { + pub fn new(name: &str, email: &str) -> EmailAddress { + let inner: Self = JsCast::unchecked_into(js_sys::Object::new()); + inner.set_name(name); + inner.set_email(email); + inner + } +} +#[wasm_bindgen] +extern "C" { + # [wasm_bindgen (extends = Object)] + #[derive(Debug, Clone, PartialEq, Eq)] + pub type SendEmail; + #[wasm_bindgen(method, catch)] + pub async fn send( + this: &SendEmail, + message: &email::EmailMessage, + ) -> Result; + #[wasm_bindgen(method, catch, js_name = "send")] + pub async fn send_with_builder( + this: &SendEmail, + builder: &SendEmailBuilder, + ) -> Result; +} +#[wasm_bindgen] +extern "C" { + # [wasm_bindgen (extends = Object)] + #[derive(Debug, Clone, PartialEq, Eq)] + pub type SendEmailBuilder; + #[wasm_bindgen(method, getter)] + pub fn from(this: &SendEmailBuilder) -> FromKind; + #[wasm_bindgen(method, setter)] + pub fn set_from(this: &SendEmailBuilder, val: &str); + #[wasm_bindgen(method, setter, js_name = "from")] + pub fn set_from_with_email_address(this: &SendEmailBuilder, val: &EmailAddress); + #[wasm_bindgen(method, getter)] + pub fn to(this: &SendEmailBuilder) -> ToKind; + #[wasm_bindgen(method, setter)] + pub fn set_to(this: &SendEmailBuilder, val: &str); + #[wasm_bindgen(method, setter, slice_to_array, js_name = "to")] + pub fn set_to_with_slice(this: &SendEmailBuilder, val: &[String]); + #[wasm_bindgen(method, getter)] + pub fn subject(this: &SendEmailBuilder) -> String; + #[wasm_bindgen(method, setter)] + pub fn set_subject(this: &SendEmailBuilder, val: &str); + #[wasm_bindgen(method, getter, js_name = "replyTo")] + pub fn reply_to(this: &SendEmailBuilder) -> Option; + #[wasm_bindgen(method, setter, js_name = "replyTo")] + pub fn set_reply_to(this: &SendEmailBuilder, val: &str); + #[wasm_bindgen(method, setter, js_name = "replyTo")] + pub fn set_reply_to_with_email_address(this: &SendEmailBuilder, val: &EmailAddress); + #[wasm_bindgen(method, getter)] + pub fn cc(this: &SendEmailBuilder) -> Option; + #[wasm_bindgen(method, setter)] + pub fn set_cc(this: &SendEmailBuilder, val: &str); + #[wasm_bindgen(method, setter, slice_to_array, js_name = "cc")] + pub fn set_cc_with_slice(this: &SendEmailBuilder, val: &[String]); + #[wasm_bindgen(method, getter)] + pub fn bcc(this: &SendEmailBuilder) -> Option; + #[wasm_bindgen(method, setter)] + pub fn set_bcc(this: &SendEmailBuilder, val: &str); + #[wasm_bindgen(method, setter, slice_to_array, js_name = "bcc")] + pub fn set_bcc_with_slice(this: &SendEmailBuilder, val: &[String]); + #[wasm_bindgen(method, getter)] + pub fn headers(this: &SendEmailBuilder) -> Option>; + #[wasm_bindgen(method, setter)] + pub fn set_headers(this: &SendEmailBuilder, val: &Object); + #[wasm_bindgen(method, getter)] + pub fn text(this: &SendEmailBuilder) -> Option; + #[wasm_bindgen(method, setter)] + pub fn set_text(this: &SendEmailBuilder, val: &str); + #[wasm_bindgen(method, getter)] + pub fn html(this: &SendEmailBuilder) -> Option; + #[wasm_bindgen(method, setter)] + pub fn set_html(this: &SendEmailBuilder, val: &str); + #[wasm_bindgen(method, getter)] + pub fn attachments(this: &SendEmailBuilder) -> Option>; + #[wasm_bindgen(method, setter, slice_to_array)] + pub fn set_attachments(this: &SendEmailBuilder, val: &[EmailAttachment]); +} +impl SendEmailBuilder { + pub fn new(from: &str, to: &str, subject: &str) -> SendEmailBuilder { + Self::builder(from, to, subject).build() + } + pub fn new_with_str_and_slice(from: &str, to: &[String], subject: &str) -> SendEmailBuilder { + Self::builder_with_str_and_slice(from, to, subject).build() + } + pub fn new_with_email_address_and_str( + from: &EmailAddress, + to: &str, + subject: &str, + ) -> SendEmailBuilder { + Self::builder_with_email_address_and_str(from, to, subject).build() + } + pub fn new_with_email_address_and_slice( + from: &EmailAddress, + to: &[String], + subject: &str, + ) -> SendEmailBuilder { + Self::builder_with_email_address_and_slice(from, to, subject).build() + } + pub fn builder(from: &str, to: &str, subject: &str) -> SendEmailBuilderBuilder { + let inner: Self = JsCast::unchecked_into(js_sys::Object::new()); + inner.set_from(from); + inner.set_to(to); + inner.set_subject(subject); + SendEmailBuilderBuilder { inner } + } + pub fn builder_with_str_and_slice( + from: &str, + to: &[String], + subject: &str, + ) -> SendEmailBuilderBuilder { + let inner: Self = JsCast::unchecked_into(js_sys::Object::new()); + inner.set_from(from); + inner.set_to_with_slice(to); + inner.set_subject(subject); + SendEmailBuilderBuilder { inner } + } + pub fn builder_with_email_address_and_str( + from: &EmailAddress, + to: &str, + subject: &str, + ) -> SendEmailBuilderBuilder { + let inner: Self = JsCast::unchecked_into(js_sys::Object::new()); + inner.set_from_with_email_address(from); + inner.set_to(to); + inner.set_subject(subject); + SendEmailBuilderBuilder { inner } + } + pub fn builder_with_email_address_and_slice( + from: &EmailAddress, + to: &[String], + subject: &str, + ) -> SendEmailBuilderBuilder { + let inner: Self = JsCast::unchecked_into(js_sys::Object::new()); + inner.set_from_with_email_address(from); + inner.set_to_with_slice(to); + inner.set_subject(subject); + SendEmailBuilderBuilder { inner } + } +} +pub struct SendEmailBuilderBuilder { + inner: SendEmailBuilder, +} +impl SendEmailBuilderBuilder { + pub fn reply_to(self, val: &str) -> Self { + self.inner.set_reply_to(val); + self + } + pub fn reply_to_with_email_address(self, val: &EmailAddress) -> Self { + self.inner.set_reply_to_with_email_address(val); + self + } + pub fn cc(self, val: &str) -> Self { + self.inner.set_cc(val); + self + } + pub fn cc_with_slice(self, val: &[String]) -> Self { + self.inner.set_cc_with_slice(val); + self + } + pub fn bcc(self, val: &str) -> Self { + self.inner.set_bcc(val); + self + } + pub fn bcc_with_slice(self, val: &[String]) -> Self { + self.inner.set_bcc_with_slice(val); + self + } + pub fn headers(self, val: &Object) -> Self { + self.inner.set_headers(val); + self + } + pub fn text(self, val: &str) -> Self { + self.inner.set_text(val); + self + } + pub fn html(self, val: &str) -> Self { + self.inner.set_html(val); + self + } + pub fn attachments(self, val: &[EmailAttachment]) -> Self { + self.inner.set_attachments(val); + self + } + pub fn build(self) -> SendEmailBuilder { + self.inner + } +} +#[wasm_bindgen] +extern "C" { + # [wasm_bindgen (extends = ExtendableEvent , extends = Object)] + #[derive(Debug, Clone, PartialEq, Eq)] + pub type EmailEvent; + #[wasm_bindgen(method, getter)] + pub fn message(this: &EmailEvent) -> ForwardableEmailMessage; +} +mod email { + use super::*; + use js_sys::*; + use wasm_bindgen::prelude::*; + #[wasm_bindgen(module = "cloudflare:email")] + extern "C" { + # [wasm_bindgen (extends = Object)] + #[derive(Debug, Clone, PartialEq, Eq)] + pub type EmailMessage; + #[wasm_bindgen(constructor, catch)] + pub fn new(from: &str, to: &str, raw: &str) -> Result; + #[wasm_bindgen(constructor, catch, js_name = "EmailMessage")] + pub fn new_with_readable_stream( + from: &str, + to: &str, + raw: &ReadableStream, + ) -> Result; + #[doc = " Envelope From attribute of the email message."] + #[wasm_bindgen(method, getter)] + pub fn from(this: &EmailMessage) -> String; + #[doc = " Envelope To attribute of the email message."] + #[wasm_bindgen(method, getter)] + pub fn to(this: &EmailMessage) -> String; + } +} +#[wasm_bindgen] +pub enum DispositionKind { + Inline = "inline", + Attachment = "attachment", +} +#[wasm_bindgen] +pub enum ContentKind { + String(String), + ArrayBuffer(ArrayBuffer), + Uint8Array(Uint8Array), +} +#[wasm_bindgen] +pub enum FromKind { + String(String), + EmailAddress(EmailAddress), +} +#[wasm_bindgen] +pub enum ToKind { + String(String), + VecOfString(Array), +} + +pub use email::EmailMessage; diff --git a/worker/src/bindings/mod.rs b/worker/src/bindings/mod.rs new file mode 100644 index 000000000..aa5f45d47 --- /dev/null +++ b/worker/src/bindings/mod.rs @@ -0,0 +1 @@ +pub mod email; diff --git a/worker/src/email.rs b/worker/src/email.rs index e89a6dd3f..0bc2be9d9 100644 --- a/worker/src/email.rs +++ b/worker/src/email.rs @@ -1,521 +1,32 @@ -// Generated by ts-gen. Do not edit. +use wasm_bindgen::JsCast; -#[allow(dead_code)] -use ::web_sys::Event; -#[allow(dead_code)] -use ::web_sys::Headers; -#[allow(dead_code)] -use ::web_sys::ReadableStream; -#[allow(unused_imports)] -use js_sys::*; -#[allow(unused_imports)] -use wasm_bindgen::prelude::*; -#[wasm_bindgen] -extern "C" { - # [wasm_bindgen (extends = Event , extends = Object)] - #[derive(Debug, Clone, PartialEq, Eq)] - pub type ExtendableEvent; - #[doc = " The **`ExtendableEvent.waitUntil()`** method tells the event dispatcher that work is ongoing."] - #[doc = ""] - #[doc = " [MDN Reference](https://developer.mozilla.org/docs/Web/API/ExtendableEvent/waitUntil)"] - #[wasm_bindgen(method, js_name = "waitUntil")] - pub fn wait_until(this: &ExtendableEvent, promise: &Promise); -} -#[wasm_bindgen] -extern "C" { - # [wasm_bindgen (extends = Object)] - #[derive(Debug, Clone, PartialEq, Eq)] - pub type EmailSendResult; - #[doc = " The Email Message ID"] - #[wasm_bindgen(method, getter, js_name = "messageId")] - pub fn message_id(this: &EmailSendResult) -> String; - #[wasm_bindgen(method, setter, js_name = "messageId")] - pub fn set_message_id(this: &EmailSendResult, val: &str); -} -impl EmailSendResult { - #[doc = " * `message_id` - The Email Message ID"] - pub fn new(message_id: &str) -> EmailSendResult { - let inner: Self = JsCast::unchecked_into(js_sys::Object::new()); - inner.set_message_id(message_id); - inner - } -} -#[wasm_bindgen] -extern "C" { - # [wasm_bindgen (extends = email :: EmailMessage , extends = Object)] - #[derive(Debug, Clone, PartialEq, Eq)] - pub type ForwardableEmailMessage; - #[doc = " Stream of the email message content."] - #[wasm_bindgen(method, getter)] - pub fn raw(this: &ForwardableEmailMessage) -> ReadableStream; - #[doc = " An [Headers object](https://developer.mozilla.org/en-US/docs/Web/API/Headers)."] - #[wasm_bindgen(method, getter)] - pub fn headers(this: &ForwardableEmailMessage) -> Headers; - #[doc = " Size of the email message content."] - #[wasm_bindgen(method, getter, js_name = "rawSize")] - pub fn raw_size(this: &ForwardableEmailMessage) -> f64; - #[doc = " Reject this email message by returning a permanent SMTP error back to the connecting client including the given reason."] - #[doc = ""] - #[doc = " * `reason` - The reject reason."] - #[doc = ""] - #[doc = " Returns: void"] - #[wasm_bindgen(method, js_name = "setReject")] - pub fn set_reject(this: &ForwardableEmailMessage, reason: &str); - #[doc = " Forward this email message to a verified destination address of the account."] - #[doc = ""] - #[doc = " * `rcptTo` - Verified destination address."] - #[doc = " * `headers` - A [Headers object](https://developer.mozilla.org/en-US/docs/Web/API/Headers)."] - #[doc = ""] - #[doc = " Returns: A promise that resolves when the email message is forwarded."] - #[wasm_bindgen(method, catch)] - pub async fn forward( - this: &ForwardableEmailMessage, - rcpt_to: &str, - ) -> Result; - #[doc = " Forward this email message to a verified destination address of the account."] - #[doc = ""] - #[doc = " * `rcptTo` - Verified destination address."] - #[doc = " * `headers` - A [Headers object](https://developer.mozilla.org/en-US/docs/Web/API/Headers)."] - #[doc = ""] - #[doc = " Returns: A promise that resolves when the email message is forwarded."] - #[wasm_bindgen(method, catch, js_name = "forward")] - pub async fn forward_with_headers( - this: &ForwardableEmailMessage, - rcpt_to: &str, - headers: &Headers, - ) -> Result; - #[doc = " Reply to the sender of this email message with a new EmailMessage object."] - #[doc = ""] - #[doc = " * `message` - The reply message."] - #[doc = ""] - #[doc = " Returns: A promise that resolves when the email message is replied."] - #[wasm_bindgen(method, catch)] - pub async fn reply( - this: &ForwardableEmailMessage, - message: &email::EmailMessage, - ) -> Result; -} -#[wasm_bindgen] -extern "C" { - # [wasm_bindgen (extends = Object)] - #[derive(Debug, Clone, PartialEq, Eq)] - pub type EmailAttachment; - #[wasm_bindgen(method, getter)] - pub fn disposition(this: &EmailAttachment) -> DispositionKind; - #[wasm_bindgen(method, setter)] - pub fn set_disposition(this: &EmailAttachment, val: &str); - #[wasm_bindgen(method, getter, js_name = "contentId")] - pub fn content_id(this: &EmailAttachment) -> Option; - #[wasm_bindgen(method, setter, js_name = "contentId")] - pub fn set_content_id(this: &EmailAttachment, val: &str); - #[wasm_bindgen(method, getter)] - pub fn filename(this: &EmailAttachment) -> String; - #[wasm_bindgen(method, setter)] - pub fn set_filename(this: &EmailAttachment, val: &str); - #[wasm_bindgen(method, getter, js_name = "type")] - pub fn type_(this: &EmailAttachment) -> String; - #[wasm_bindgen(method, setter)] - pub fn set_type(this: &EmailAttachment, val: &str); - #[wasm_bindgen(method, getter)] - pub fn content(this: &EmailAttachment) -> ContentKind; - #[wasm_bindgen(method, setter)] - pub fn set_content(this: &EmailAttachment, val: &str); - #[wasm_bindgen(method, setter, js_name = "content")] - pub fn set_content_with_array_buffer(this: &EmailAttachment, val: &ArrayBuffer); - #[wasm_bindgen(method, setter, js_name = "content")] - pub fn set_content_with_typed_array(this: &EmailAttachment, val: &T); -} -impl EmailAttachment { - #[doc = " ## Inlined fields"] - #[doc = ""] - #[doc = " * `disposition: \"inline\"`"] - pub fn new_inline( - content_id: &str, - filename: &str, - r#type: &str, - content: &str, - ) -> EmailAttachment { - let inner: Self = JsCast::unchecked_into(js_sys::Object::new()); - inner.set_disposition("inline"); - inner.set_content_id(content_id); - inner.set_filename(filename); - inner.set_type(r#type); - inner.set_content(content); - inner - } - #[doc = " ## Inlined fields"] - #[doc = ""] - #[doc = " * `disposition: \"inline\"`"] - pub fn new_inline_with_array_buffer( - content_id: &str, - filename: &str, - r#type: &str, - content: &ArrayBuffer, - ) -> EmailAttachment { - let inner: Self = JsCast::unchecked_into(js_sys::Object::new()); - inner.set_disposition("inline"); - inner.set_content_id(content_id); - inner.set_filename(filename); - inner.set_type(r#type); - inner.set_content_with_array_buffer(content); - inner - } - #[doc = " ## Inlined fields"] - #[doc = ""] - #[doc = " * `disposition: \"inline\"`"] - pub fn new_inline_with_typed_array( - content_id: &str, - filename: &str, - r#type: &str, - content: &T, - ) -> EmailAttachment { - let inner: Self = JsCast::unchecked_into(js_sys::Object::new()); - inner.set_disposition("inline"); - inner.set_content_id(content_id); - inner.set_filename(filename); - inner.set_type(r#type); - inner.set_content_with_typed_array(content); - inner - } - #[doc = " ## Inlined fields"] - #[doc = ""] - #[doc = " * `disposition: \"attachment\"`"] - pub fn new_attachment(filename: &str, r#type: &str, content: &str) -> EmailAttachment { - Self::builder_attachment(filename, r#type, content).build() - } - #[doc = " ## Inlined fields"] - #[doc = ""] - #[doc = " * `disposition: \"attachment\"`"] - pub fn new_attachment_with_array_buffer( - filename: &str, - r#type: &str, - content: &ArrayBuffer, - ) -> EmailAttachment { - Self::builder_attachment_with_array_buffer(filename, r#type, content).build() - } - #[doc = " ## Inlined fields"] - #[doc = ""] - #[doc = " * `disposition: \"attachment\"`"] - pub fn new_attachment_with_typed_array( - filename: &str, - r#type: &str, - content: &T, - ) -> EmailAttachment { - Self::builder_attachment_with_typed_array(filename, r#type, content).build() - } - #[doc = " ## Inlined fields"] - #[doc = ""] - #[doc = " * `disposition: \"attachment\"`"] - pub fn builder_attachment( - filename: &str, - r#type: &str, - content: &str, - ) -> EmailAttachmentBuilder { - let inner: Self = JsCast::unchecked_into(js_sys::Object::new()); - inner.set_disposition("attachment"); - inner.set_filename(filename); - inner.set_type(r#type); - inner.set_content(content); - EmailAttachmentBuilder { inner } - } - #[doc = " ## Inlined fields"] - #[doc = ""] - #[doc = " * `disposition: \"attachment\"`"] - pub fn builder_attachment_with_array_buffer( - filename: &str, - r#type: &str, - content: &ArrayBuffer, - ) -> EmailAttachmentBuilder { - let inner: Self = JsCast::unchecked_into(js_sys::Object::new()); - inner.set_disposition("attachment"); - inner.set_filename(filename); - inner.set_type(r#type); - inner.set_content_with_array_buffer(content); - EmailAttachmentBuilder { inner } - } - #[doc = " ## Inlined fields"] - #[doc = ""] - #[doc = " * `disposition: \"attachment\"`"] - pub fn builder_attachment_with_typed_array( - filename: &str, - r#type: &str, - content: &T, - ) -> EmailAttachmentBuilder { - let inner: Self = JsCast::unchecked_into(js_sys::Object::new()); - inner.set_disposition("attachment"); - inner.set_filename(filename); - inner.set_type(r#type); - inner.set_content_with_typed_array(content); - EmailAttachmentBuilder { inner } - } -} -pub struct EmailAttachmentBuilder { - inner: EmailAttachment, -} -impl EmailAttachmentBuilder { - pub fn content_id(self, val: &str) -> Self { - self.inner.set_content_id(val); - self - } - pub fn build(self) -> EmailAttachment { - self.inner - } -} -#[wasm_bindgen] -extern "C" { - # [wasm_bindgen (extends = Object)] - #[derive(Debug, Clone, PartialEq, Eq)] - pub type EmailAddress; - #[wasm_bindgen(method, getter)] - pub fn name(this: &EmailAddress) -> String; - #[wasm_bindgen(method, setter)] - pub fn set_name(this: &EmailAddress, val: &str); - #[wasm_bindgen(method, getter)] - pub fn email(this: &EmailAddress) -> String; - #[wasm_bindgen(method, setter)] - pub fn set_email(this: &EmailAddress, val: &str); -} -impl EmailAddress { - pub fn new(name: &str, email: &str) -> EmailAddress { - let inner: Self = JsCast::unchecked_into(js_sys::Object::new()); - inner.set_name(name); - inner.set_email(email); - inner - } -} -#[wasm_bindgen] -extern "C" { - # [wasm_bindgen (extends = Object)] - #[derive(Debug, Clone, PartialEq, Eq)] - pub type SendEmail; - #[wasm_bindgen(method, catch)] - pub async fn send( - this: &SendEmail, - message: &email::EmailMessage, - ) -> Result; - #[wasm_bindgen(method, catch, js_name = "send")] - pub async fn send_with_builder( - this: &SendEmail, - builder: &SendEmailBuilder, - ) -> Result; -} -#[wasm_bindgen] -extern "C" { - # [wasm_bindgen (extends = Object)] - #[derive(Debug, Clone, PartialEq, Eq)] - pub type SendEmailBuilder; - #[wasm_bindgen(method, getter)] - pub fn from(this: &SendEmailBuilder) -> FromKind; - #[wasm_bindgen(method, setter)] - pub fn set_from(this: &SendEmailBuilder, val: &str); - #[wasm_bindgen(method, setter, js_name = "from")] - pub fn set_from_with_email_address(this: &SendEmailBuilder, val: &EmailAddress); - #[wasm_bindgen(method, getter)] - pub fn to(this: &SendEmailBuilder) -> ToKind; - #[wasm_bindgen(method, setter)] - pub fn set_to(this: &SendEmailBuilder, val: &str); - #[wasm_bindgen(method, setter, slice_to_array, js_name = "to")] - pub fn set_to_with_slice(this: &SendEmailBuilder, val: &[String]); - #[wasm_bindgen(method, getter)] - pub fn subject(this: &SendEmailBuilder) -> String; - #[wasm_bindgen(method, setter)] - pub fn set_subject(this: &SendEmailBuilder, val: &str); - #[wasm_bindgen(method, getter, js_name = "replyTo")] - pub fn reply_to(this: &SendEmailBuilder) -> Option; - #[wasm_bindgen(method, setter, js_name = "replyTo")] - pub fn set_reply_to(this: &SendEmailBuilder, val: &str); - #[wasm_bindgen(method, setter, js_name = "replyTo")] - pub fn set_reply_to_with_email_address(this: &SendEmailBuilder, val: &EmailAddress); - #[wasm_bindgen(method, getter)] - pub fn cc(this: &SendEmailBuilder) -> Option; - #[wasm_bindgen(method, setter)] - pub fn set_cc(this: &SendEmailBuilder, val: &str); - #[wasm_bindgen(method, setter, slice_to_array, js_name = "cc")] - pub fn set_cc_with_slice(this: &SendEmailBuilder, val: &[String]); - #[wasm_bindgen(method, getter)] - pub fn bcc(this: &SendEmailBuilder) -> Option; - #[wasm_bindgen(method, setter)] - pub fn set_bcc(this: &SendEmailBuilder, val: &str); - #[wasm_bindgen(method, setter, slice_to_array, js_name = "bcc")] - pub fn set_bcc_with_slice(this: &SendEmailBuilder, val: &[String]); - #[wasm_bindgen(method, getter)] - pub fn headers(this: &SendEmailBuilder) -> Option>; - #[wasm_bindgen(method, setter)] - pub fn set_headers(this: &SendEmailBuilder, val: &Object); - #[wasm_bindgen(method, getter)] - pub fn text(this: &SendEmailBuilder) -> Option; - #[wasm_bindgen(method, setter)] - pub fn set_text(this: &SendEmailBuilder, val: &str); - #[wasm_bindgen(method, getter)] - pub fn html(this: &SendEmailBuilder) -> Option; - #[wasm_bindgen(method, setter)] - pub fn set_html(this: &SendEmailBuilder, val: &str); - #[wasm_bindgen(method, getter)] - pub fn attachments(this: &SendEmailBuilder) -> Option>; - #[wasm_bindgen(method, setter, slice_to_array)] - pub fn set_attachments(this: &SendEmailBuilder, val: &[EmailAttachment]); -} -impl SendEmailBuilder { - pub fn new(from: &str, to: &str, subject: &str) -> SendEmailBuilder { - Self::builder(from, to, subject).build() - } - pub fn new_with_str_and_slice(from: &str, to: &[String], subject: &str) -> SendEmailBuilder { - Self::builder_with_str_and_slice(from, to, subject).build() - } - pub fn new_with_email_address_and_str( - from: &EmailAddress, - to: &str, - subject: &str, - ) -> SendEmailBuilder { - Self::builder_with_email_address_and_str(from, to, subject).build() - } - pub fn new_with_email_address_and_slice( - from: &EmailAddress, - to: &[String], - subject: &str, - ) -> SendEmailBuilder { - Self::builder_with_email_address_and_slice(from, to, subject).build() - } - pub fn builder(from: &str, to: &str, subject: &str) -> SendEmailBuilderBuilder { - let inner: Self = JsCast::unchecked_into(js_sys::Object::new()); - inner.set_from(from); - inner.set_to(to); - inner.set_subject(subject); - SendEmailBuilderBuilder { inner } - } - pub fn builder_with_str_and_slice( - from: &str, - to: &[String], - subject: &str, - ) -> SendEmailBuilderBuilder { - let inner: Self = JsCast::unchecked_into(js_sys::Object::new()); - inner.set_from(from); - inner.set_to_with_slice(to); - inner.set_subject(subject); - SendEmailBuilderBuilder { inner } - } - pub fn builder_with_email_address_and_str( - from: &EmailAddress, - to: &str, - subject: &str, - ) -> SendEmailBuilderBuilder { - let inner: Self = JsCast::unchecked_into(js_sys::Object::new()); - inner.set_from_with_email_address(from); - inner.set_to(to); - inner.set_subject(subject); - SendEmailBuilderBuilder { inner } - } - pub fn builder_with_email_address_and_slice( - from: &EmailAddress, - to: &[String], - subject: &str, - ) -> SendEmailBuilderBuilder { - let inner: Self = JsCast::unchecked_into(js_sys::Object::new()); - inner.set_from_with_email_address(from); - inner.set_to_with_slice(to); - inner.set_subject(subject); - SendEmailBuilderBuilder { inner } - } -} -pub struct SendEmailBuilderBuilder { - inner: SendEmailBuilder, -} -impl SendEmailBuilderBuilder { - pub fn reply_to(self, val: &str) -> Self { - self.inner.set_reply_to(val); - self - } - pub fn reply_to_with_email_address(self, val: &EmailAddress) -> Self { - self.inner.set_reply_to_with_email_address(val); - self - } - pub fn cc(self, val: &str) -> Self { - self.inner.set_cc(val); - self - } - pub fn cc_with_slice(self, val: &[String]) -> Self { - self.inner.set_cc_with_slice(val); - self - } - pub fn bcc(self, val: &str) -> Self { - self.inner.set_bcc(val); - self - } - pub fn bcc_with_slice(self, val: &[String]) -> Self { - self.inner.set_bcc_with_slice(val); - self - } - pub fn headers(self, val: &Object) -> Self { - self.inner.set_headers(val); - self - } - pub fn text(self, val: &str) -> Self { - self.inner.set_text(val); - self - } - pub fn html(self, val: &str) -> Self { - self.inner.set_html(val); - self - } - pub fn attachments(self, val: &[EmailAttachment]) -> Self { - self.inner.set_attachments(val); - self - } - pub fn build(self) -> SendEmailBuilder { - self.inner +pub use crate::bindings::email::*; +use crate::{EnvBinding, Result}; + +impl EnvBinding for SendEmail { + const TYPE_NAME: &'static str = "SendEmail"; + + // `SendEmail` is a TypeScript interface, not a class — the runtime + // doesn't expose a `SendEmail` global for the default + // `constructor.name` check to match against. The TS types are + // authoritative: if `env.EMAIL` is bound to a SendEmail per + // `wrangler.toml`, the runtime hands us the right shape, so we + // skip the check and `unchecked_into`. + fn get(val: wasm_bindgen::JsValue) -> Result { + Ok(val.unchecked_into()) } } -#[wasm_bindgen] -extern "C" { - # [wasm_bindgen (extends = ExtendableEvent , extends = Object)] - #[derive(Debug, Clone, PartialEq, Eq)] - pub type EmailEvent; - #[wasm_bindgen(method, getter)] - pub fn message(this: &EmailEvent) -> ForwardableEmailMessage; -} -pub mod email { - use super::*; - use js_sys::*; - use wasm_bindgen::prelude::*; - #[wasm_bindgen(module = "cloudflare:email")] - extern "C" { - # [wasm_bindgen (extends = Object)] - #[derive(Debug, Clone, PartialEq, Eq)] - pub type EmailMessage; - #[wasm_bindgen(constructor, catch)] - pub fn new(from: &str, to: &str, raw: &str) -> Result; - #[wasm_bindgen(constructor, catch, js_name = "EmailMessage")] - pub fn new_with_readable_stream( - from: &str, - to: &str, - raw: &ReadableStream, - ) -> Result; - #[doc = " Envelope From attribute of the email message."] - #[wasm_bindgen(method, getter)] - pub fn from(this: &EmailMessage) -> String; - #[doc = " Envelope To attribute of the email message."] - #[wasm_bindgen(method, getter)] - pub fn to(this: &EmailMessage) -> String; + +#[cfg(test)] +mod send_check { + // `SendEmail` is `Send` automatically — wasm-bindgen makes `JsValue` + // `Send + Sync` and every extern `pub type` in `email.rs` carries that + // through. This compile-time check guards against an upstream + // regression. + use super::SendEmail; + fn _assert_send() {} + #[allow(dead_code)] + fn _check() { + _assert_send::(); } } -#[wasm_bindgen] -pub enum DispositionKind { - Inline = "inline", - Attachment = "attachment", -} -#[wasm_bindgen] -pub enum ContentKind { - String(String), - ArrayBuffer(ArrayBuffer), - Uint8Array(Uint8Array), -} -#[wasm_bindgen] -pub enum FromKind { - String(String), - EmailAddress(EmailAddress), -} -#[wasm_bindgen] -pub enum ToKind { - String(String), - VecOfString(Array), -} diff --git a/worker/src/env.rs b/worker/src/env.rs index 72502d96b..61d02c879 100644 --- a/worker/src/env.rs +++ b/worker/src/env.rs @@ -3,9 +3,9 @@ use std::fmt::Display; use crate::analytics_engine::AnalyticsEngineDataset; #[cfg(feature = "d1")] use crate::d1::D1Database; +use crate::email::SendEmail; use crate::kv::KvStore; use crate::rate_limit::RateLimiter; -use crate::send_email::SendEmail; use crate::Ai; #[cfg(feature = "queue")] use crate::Queue; diff --git a/worker/src/lib.rs b/worker/src/lib.rs index c54129ca8..a6cc5ff72 100644 --- a/worker/src/lib.rs +++ b/worker/src/lib.rs @@ -193,14 +193,25 @@ pub use crate::response::{EncodeBody, IntoResponse, Response, ResponseBody, Resp pub use crate::router::{RouteContext, RouteParams, Router}; pub use crate::schedule::*; pub use crate::secret_store::SecretStore; -pub use crate::send_email::{ - EmailAddress, EmailAttachment, EmailMessage, EmailSendResult, SendEmail, SendEmailBuilder, -}; pub use crate::socket::*; pub use crate::streams::*; pub use crate::version::*; pub use crate::websocket::*; +// Generated by `chomp build:types` from types/email.d.ts. Keep it scoped here +// and let the high-level `send_email` module re-export the slice consumers +// need. The codegen produces builder types without `Debug` and an inner +// `email` module that triggers `clippy::module_inception`; allow both since +// they're owned by ts-gen, not us. +#[allow( + unused_imports, + dead_code, + missing_debug_implementations, + clippy::module_inception, + clippy::new_without_default +)] +mod bindings; + mod abort; mod ai; mod analytics_engine; @@ -219,19 +230,7 @@ mod date; mod delay; pub mod durable; mod dynamic_dispatch; -// Generated by `chomp build:types` from types/email.d.ts. Keep it scoped here -// and let the high-level `send_email` module re-export the slice consumers -// need. The codegen produces builder types without `Debug` and an inner -// `email` module that triggers `clippy::module_inception`; allow both since -// they're owned by ts-gen, not us. -#[allow( - unused_imports, - dead_code, - missing_debug_implementations, - clippy::module_inception, - clippy::new_without_default -)] -mod email; +pub mod email; mod env; mod error; mod fetcher; @@ -252,7 +251,6 @@ mod router; mod schedule; mod secret_store; pub mod send; -mod send_email; pub mod signal; mod socket; mod sql; diff --git a/worker/src/send_email.rs b/worker/src/send_email.rs deleted file mode 100644 index 7d1862c23..000000000 --- a/worker/src/send_email.rs +++ /dev/null @@ -1,47 +0,0 @@ -use wasm_bindgen::JsCast; - -use crate::{EnvBinding, Result}; - -// The full email surface comes from the auto-generated `crate::email` -// module (`chomp build:types` from `types/email.d.ts`). This file only -// adds the [`EnvBinding`] trait impl on top of the auto-gen `SendEmail` -// extern type so `Env::send_email("EMAIL")` resolves cleanly. -// -// `EmailMessage` is the constructor class imported from -// `cloudflare:email`, used to build raw-MIME messages and pass to -// `SendEmail.send(message)`. It also doubles as the instance-shape -// type referenced by `ForwardableEmailMessage` and `reply()` — same JS -// object collapsed to a single Rust type, see the d.ts EDIT note for -// the naming rationale. -pub use crate::email::email::EmailMessage; -pub use crate::email::{ - EmailAddress, EmailAttachment, EmailSendResult, SendEmail, SendEmailBuilder, -}; - -impl EnvBinding for SendEmail { - const TYPE_NAME: &'static str = "SendEmail"; - - // `SendEmail` is a TypeScript interface, not a class — the runtime - // doesn't expose a `SendEmail` global for the default - // `constructor.name` check to match against. The TS types are - // authoritative: if `env.EMAIL` is bound to a SendEmail per - // `wrangler.toml`, the runtime hands us the right shape, so we - // skip the check and `unchecked_into`. - fn get(val: wasm_bindgen::JsValue) -> Result { - Ok(val.unchecked_into()) - } -} - -#[cfg(test)] -mod send_check { - // `SendEmail` is `Send` automatically — wasm-bindgen makes `JsValue` - // `Send + Sync` and every extern `pub type` in `email.rs` carries that - // through. This compile-time check guards against an upstream - // regression. - use super::SendEmail; - fn _assert_send() {} - #[allow(dead_code)] - fn _check() { - _assert_send::(); - } -} From 4f8dba62538a15f19d52ac8f91d7da4fabbedc7e Mon Sep 17 00:00:00 2001 From: Guy Bedford Date: Fri, 8 May 2026 18:13:01 -0700 Subject: [PATCH 2/2] fixup examples --- examples/send-email/src/lib.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/examples/send-email/src/lib.rs b/examples/send-email/src/lib.rs index d28f131ba..16e9391f3 100644 --- a/examples/send-email/src/lib.rs +++ b/examples/send-email/src/lib.rs @@ -19,9 +19,9 @@ async fn fetch(req: Request, env: Env, _ctx: Context) -> Result { Response::ok(format!("sent: {}", result.message_id())) } -async fn send_structured(sender: &SendEmail) -> Result { - let from = EmailAddress::new("Sending email test", SENDER); - let builder = SendEmailBuilder::builder_with_email_address_and_str( +async fn send_structured(sender: &email::SendEmail) -> Result { + let from = email::EmailAddress::new("Sending email test", SENDER); + let builder = email::SendEmailBuilder::builder_with_email_address_and_str( &from, RECIPIENT, "An email generated in a Worker", @@ -33,7 +33,7 @@ async fn send_structured(sender: &SendEmail) -> Result { Ok(sender.send_with_builder(&builder).await?) } -async fn send_raw_mime(sender: &SendEmail) -> Result { +async fn send_raw_mime(sender: &email::SendEmail) -> Result { // mail-builder's auto-generated `Date:` and `Message-ID:` headers rely on // `SystemTime::now()` and `gethostname`, neither of which work on // `wasm32-unknown-unknown`. https://github.com/stalwartlabs/mail-builder/pull/26 @@ -50,6 +50,6 @@ async fn send_raw_mime(sender: &SendEmail) -> Result { .write_to_string() .map_err(|e| Error::RustError(e.to_string()))?; - let message = EmailMessage::new(SENDER, RECIPIENT, &raw)?; + let message = email::EmailMessage::new(SENDER, RECIPIENT, &raw)?; Ok(sender.send(&message).await?) }