Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down
55 changes: 54 additions & 1 deletion src/batch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Comment on lines +23 to +24

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P3: Users can still infer from this CreateEmailBaseOptions documentation that all of the shared send-email fields work in a batch, including attachments and scheduled_at, even though the batch endpoint rejects or ignores them. A concise limitation note here would prevent misuse of the shared builder.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At src/batch.rs, line 23:

<comment>Users can still infer from this `CreateEmailBaseOptions` documentation that all of the shared send-email fields work in a batch, including `attachments` and `scheduled_at`, even though the batch endpoint rejects or ignores them. A concise limitation note here would prevent misuse of the shared builder.</comment>

<file context>
@@ -20,8 +20,8 @@ impl BatchSvc {
     ///
-    /// Each [`CreateEmailBaseOptions`] in the batch supports `scheduled_at`, `tags`,
-    /// and `attachments`, in addition to the other send-email body parameters.
+    /// Each [`CreateEmailBaseOptions`] in the batch supports `tags`, in addition to
+    /// the other send-email body parameters.
     ///
</file context>
Suggested change
/// Each [`CreateEmailBaseOptions`] in the batch supports `tags`, in addition to
/// the other send-email body parameters.
/// Batch sends support `tags` on each [`CreateEmailBaseOptions`]. The
/// `attachments` and `scheduled_at` fields are not supported.

///
/// <https://resend.com/docs/api-reference/emails/send-batch-emails>
#[maybe_async::maybe_async]
pub async fn send<T>(
Expand Down Expand Up @@ -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)]
Expand Down Expand Up @@ -323,4 +326,54 @@ mod test {

Ok(())
}

#[test]
fn serialize_tags() {
use serde_json::json;

let email = CreateEmailBaseOptions::new(
"Acme <onboarding@resend.dev>",
["delivered@resend.dev"],
"hello world",
)
.with_html("<h1>it works!</h1>")
.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 <onboarding@resend.dev>",
["delivered@resend.dev"],
"hello world",
)
.with_html("<h1>it works!</h1>")
.with_tag(Tag::new("category", "confirm_email")),
CreateEmailBaseOptions::new(
"Acme <onboarding@resend.dev>",
["delivered@resend.dev"],
"world hello",
)
.with_html("<p>it works!</p>")
.with_tag(Tag::new("category", "confirm_email")),
];

let emails = resend.batch.send(emails).await?;
assert_eq!(emails.len(), 2);

Ok(())
}
}