Skip to content

Conversation

@michelle0927
Copy link
Collaborator

@michelle0927 michelle0927 commented Sep 4, 2025

Resolves #18213

Summary by CodeRabbit

  • New Features

    • Send Email action now supports attachments: upload files or provide base64-encoded attachments with filenames.
    • File attachments are handled and included in the email payload alongside existing fields.
  • Bug Fixes

    • Corrected CC field label from "CCc" to "Cc".
  • Chores

    • Bumped Send Email action version to 0.0.2.
    • Updated Resend components package version.

@vercel
Copy link

vercel bot commented Sep 4, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

2 Skipped Deployments
Project Deployment Preview Comments Updated (UTC)
pipedream-docs Ignored Ignored Sep 4, 2025 10:19pm
pipedream-docs-redirect-do-not-edit Ignored Ignored Sep 4, 2025 10:19pm

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Sep 4, 2025

Walkthrough

Adds attachment support to the Resend Send Email action: accepts file paths and base64 inputs, constructs an attachments array (from resolved file streams and base64 pairs), validates base64 filename pairing, adds a stream-to-buffer helper, imports file utilities and ConfigurationError, and bumps action and package versions.

Changes

Cohort / File(s) Summary
Resend Send Email action enhancements
components/resend/actions/send-email/send-email.ts
Adds props attachmentFiles, attachmentsBase64, base64AttachmentFilenames; resolves file streams with getFileStreamAndMetadata, converts streams to base64 with streamToBuffer, validates base64 filename array lengths (throws ConfigurationError on mismatch), builds attachments array for API payload, corrects "CCc" → "Cc", and bumps action version to 0.0.2.
Resend package version bump
components/resend/package.json
Updates package version from 0.1.1 to 0.1.2.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor U as User
  participant A as SendEmail Action
  participant FS as getFileStreamAndMetadata
  participant B as streamToBuffer
  participant R as Resend API

  U->>A: run(props including attachmentFiles, attachmentsBase64, base64AttachmentFilenames)
  alt attachmentsBase64 provided
    A->>A: Validate lengths match
    alt mismatch
      A-->>U: throw ConfigurationError
    end
  end

  opt attachmentFiles provided
    loop for each filePath
      A->>FS: getFileStreamAndMetadata(filePath)
      FS-->>A: { stream, metadata(name) }
      A->>B: streamToBuffer(stream)
      B-->>A: Buffer
      A->>A: encode Buffer → base64, push { filename: metadata.name, content: base64 } to attachments
    end
  end

  opt base64 attachments provided
    A->>A: pair filenames with base64 strings, push { filename, content } to attachments
  end

  A->>R: POST /emails (body includes attachments)
  R-->>A: response
  A-->>U: result
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Assessment against linked issues

Objective Addressed Explanation
Add attachment support to Resend Send Email action, including base64 support [#18213]

Poem

I bundled bytes with hop and cheer,
From files and base64 both near—
Filenames tidy, payloads light,
Off they go into the night.
A furry nod — version bumped right! 🐇✉️

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch issue-18213

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore or @coderabbit ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
components/resend/actions/send-email/send-email.ts (1)

46-46: Fix label typo: "CCc" → "Cc"

User-facing label is misspelled.

-      label: "CCc",
+      label: "Cc",
🧹 Nitpick comments (6)
components/resend/actions/send-email/send-email.ts (6)

96-96: Add a type to attachments for better TS safety

Explicit typing prevents accidental shape drift.

-    const attachments = [];
+    const attachments: { filename: string; content: string }[] = [];

82-89: Type the streamToBuffer parameter

Improves editor/TS checks and intent clarity.

-    async streamToBuffer(stream): Promise<Buffer> {
+    async streamToBuffer(stream: NodeJS.ReadableStream): Promise<Buffer> {

123-136: Only include attachments when non-empty

Keeps payload minimal and avoids sending an empty array.

-    const params = {
-      $,
-      data: {
-        from,
-        to,
-        subject,
-        html,
-        text,
-        cc,
-        bcc,
-        reply_to: replyTo,
-        attachments,
-      },
-    };
+    const data: Record<string, any> = {
+      from,
+      to,
+      subject,
+      html,
+      text,
+      cc,
+      bcc,
+      reply_to: replyTo,
+    };
+    if (attachments.length) data.attachments = attachments;
+    const params = { $, data };

45-45: Consider arrays for cc/bcc/reply-to to match API

Resend accepts string | string[] for cc, bcc, and reply_to. Mirroring to as arrays improves consistency. If you prefer not to change the UI, consider accepting both and normalizing before send. (resend.com)

-    cc: {
-      type: "string",
+    cc: {
+      type: "string[]",
@@
-    bcc: {
-      type: "string",
+    bcc: {
+      type: "string[]",
@@
-    replyTo: {
-      type: "string",
+    replyTo: {
+      type: "string[]",

Also applies to: 51-51, 57-57


96-109: Optional: include content_type when available

If metadata.type is present, pass it as content_type to improve client previews. (resend.com)

-        attachments.push({
-          filename: metadata.name,
-          content: base64,
-        });
+        attachments.push({
+          filename: metadata.name,
+          content: base64,
+          ...(metadata.type ? { content_type: metadata.type } : {}),
+        });

62-79: Optional: fail fast on oversize attachments

Resend limits emails to 40MB total after Base64 encoding; consider validating cumulative size and throwing a helpful error. (resend.com)

Also applies to: 111-121

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between e3d9866 and 137b88f.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (2)
  • components/resend/actions/send-email/send-email.ts (3 hunks)
  • components/resend/package.json (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: Publish TypeScript components
  • GitHub Check: Verify TypeScript components
  • GitHub Check: pnpm publish
  • GitHub Check: Lint Code Base
🔇 Additional comments (3)
components/resend/package.json (1)

3-3: Version bump LGTM

Package version updated to 0.1.2 — no concerns.

components/resend/actions/send-email/send-email.ts (2)

3-5: New imports LGTM

Using getFileStreamAndMetadata and ConfigurationError is appropriate for the new attachment flow.


12-12: Action version bump LGTM

Bumped to 0.0.2 as expected for the new feature.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

♻️ Duplicate comments (1)
components/resend/actions/send-email/send-email.ts (1)

111-121: Guard against undefined base64AttachmentFilenames (prevents TypeError) and improve error message

If attachmentsBase64 is set without filenames, base64AttachmentFilenames.length throws. Also keep the loop zero-based (good) and retain filename.

-    if (attachmentsBase64) {
-      if (attachmentsBase64.length !== base64AttachmentFilenames.length) {
-        throw new ConfigurationError("The number of base64-encoded attachments must match the number of base64-encoded attachment filenames");
-      }
-      for (let i = 0; i < attachmentsBase64.length; i++) {
-        attachments.push({
-          filename: base64AttachmentFilenames[i],
-          content: attachmentsBase64[i],
-        });
-      }
-    }
+    if (attachmentsBase64?.length) {
+      if (!base64AttachmentFilenames?.length ||
+          attachmentsBase64.length !== base64AttachmentFilenames.length) {
+        throw new ConfigurationError(
+          `The number of base64 attachments must match the number of filenames (attachmentsBase64=${attachmentsBase64.length}, base64AttachmentFilenames=${base64AttachmentFilenames?.length ?? 0})`,
+        );
+      }
+      for (let i = 0; i < attachmentsBase64.length; i++) {
+        attachments.push({
+          filename: base64AttachmentFilenames[i],
+          content: attachmentsBase64[i],
+        });
+      }
+    }
🧹 Nitpick comments (4)
components/resend/actions/send-email/send-email.ts (4)

82-89: Type the stream param for clarity

Minor: add an explicit Node stream type.

-    async streamToBuffer(stream): Promise<Buffer> {
+    async streamToBuffer(stream: NodeJS.ReadableStream): Promise<Buffer> {

97-109: Parallelize file reads and add filename fallback

Reading files sequentially can be slow with many attachments. Also guard when metadata.name is missing.

-    if (attachmentFiles) {
-      for (const file of attachmentFiles) {
-        const {
-          stream, metadata,
-        } = await getFileStreamAndMetadata(file);
-        const buffer = await this.streamToBuffer(stream);
-        const base64 = buffer.toString("base64");
-        attachments.push({
-          filename: metadata.name,
-          content: base64,
-        });
-      }
-    }
+    if (attachmentFiles?.length) {
+      const fileAttachments = await Promise.all(attachmentFiles.map(async (file) => {
+        const { stream, metadata } = await getFileStreamAndMetadata(file);
+        const buffer = await this.streamToBuffer(stream);
+        return {
+          filename: metadata?.name ?? "attachment",
+          content: buffer.toString("base64"),
+        };
+      }));
+      attachments.push(...fileAttachments);
+    }

123-136: Avoid sending an empty attachments array

Some APIs are picky about empty arrays. Only include the field when non-empty.

-    const params = {
-      $,
-      data: {
-        from,
-        to,
-        subject,
-        html,
-        text,
-        cc,
-        bcc,
-        reply_to: replyTo,
-        attachments,
-      },
-    };
+    const data: Record<string, any> = {
+      from,
+      to,
+      subject,
+      html,
+      text,
+      cc,
+      bcc,
+      reply_to: replyTo,
+    };
+    if (attachments.length) data.attachments = attachments;
+    const params = { $, data };

69-79: Optional: accept data URLs for attachmentsBase64

Users often paste data URLs (e.g., "data:application/pdf;base64,...."). Strip the prefix before sending.

-      for (let i = 0; i < attachmentsBase64.length; i++) {
-        attachments.push({
-          filename: base64AttachmentFilenames[i],
-          content: attachmentsBase64[i],
-        });
-      }
+      for (let i = 0; i < attachmentsBase64.length; i++) {
+        const raw = attachmentsBase64[i] ?? "";
+        const content = raw.startsWith("data:") ? (raw.split(",", 2)[1] ?? "") : raw;
+        attachments.push({
+          filename: base64AttachmentFilenames[i],
+          content,
+        });
+      }

Also applies to: 111-121

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 137b88f and e8f54d4.

📒 Files selected for processing (1)
  • components/resend/actions/send-email/send-email.ts (4 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: Lint Code Base
  • GitHub Check: Publish TypeScript components
  • GitHub Check: Verify TypeScript components
🔇 Additional comments (2)
components/resend/actions/send-email/send-email.ts (2)

3-5: Good import additions

Importing getFileStreamAndMetadata and ConfigurationError is correct and used appropriately.


46-46: Typo fix LGTM

Label corrected to "Cc".

@vunguyenhung vunguyenhung merged commit a842fdf into master Sep 6, 2025
10 checks passed
@vunguyenhung vunguyenhung deleted the issue-18213 branch September 6, 2025 07:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[ACTION] Attachment support for Resend "Send Email" Action

4 participants