diff --git a/CHANGELOG.md b/CHANGELOG.md index e021dd2..1cc88a8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ and this project adheres to ### Added +- batch send support for `tags` on [`CreateEmailBaseOptions`](https://docs.rs/resend-rs/latest/resend_rs/types/struct.CreateEmailBaseOptions.html) - add `message_id` to `Email` and webhook `EmailBody` types (https://github.com/resend/resend-rust/pull/77) diff --git a/src/batch.rs b/src/batch.rs index d6d33e7..541a43c 100644 --- a/src/batch.rs +++ b/src/batch.rs @@ -20,6 +20,9 @@ impl BatchSvc { /// Instead of sending one email per HTTP request, we provide a batching endpoint /// that permits you to send up to 100 emails in a single API call. /// + /// Each [`CreateEmailBaseOptions`] in the batch supports `tags`, in addition to + /// the other send-email body parameters. + /// /// #[maybe_async::maybe_async] pub async fn send( @@ -123,7 +126,7 @@ mod test { use crate::test::{CLIENT, DebugResult}; use crate::types::{ BatchValidation, CreateEmailBaseOptions, CreateTemplateOptions, EmailEvent, EmailTemplate, - Variable, VariableType, + Tag, Variable, VariableType, }; #[tokio_shared_rt::test(shared = true)] @@ -323,4 +326,54 @@ mod test { Ok(()) } + + #[test] + fn serialize_tags() { + use serde_json::json; + + let email = CreateEmailBaseOptions::new( + "Acme ", + ["delivered@resend.dev"], + "hello world", + ) + .with_html("

it works!

") + .with_tag(Tag::new("category", "confirm_email")); + + let emails = vec![email]; + let value = serde_json::to_value(&emails).unwrap(); + + assert_eq!( + value[0]["tags"], + json!([{"name": "category", "value": "confirm_email"}]) + ); + } + + #[tokio_shared_rt::test(shared = true)] + #[cfg(not(feature = "blocking"))] + async fn tags() -> DebugResult<()> { + let resend = &*CLIENT; + std::thread::sleep(std::time::Duration::from_secs(1)); + + let emails = vec![ + CreateEmailBaseOptions::new( + "Acme ", + ["delivered@resend.dev"], + "hello world", + ) + .with_html("

it works!

") + .with_tag(Tag::new("category", "confirm_email")), + CreateEmailBaseOptions::new( + "Acme ", + ["delivered@resend.dev"], + "world hello", + ) + .with_html("

it works!

") + .with_tag(Tag::new("category", "confirm_email")), + ]; + + let emails = resend.batch.send(emails).await?; + assert_eq!(emails.len(), 2); + + Ok(()) + } }