Skip to content

Conversation

@nsouzaco
Copy link

Fixes #20832

Users can now use expressions like ={{ $('NodeName').item.binary.data }} in the attachments parameter, in addition to the existing comma-separated string format.

Changes:

  • Enhanced attachment processing to handle string, IBinaryData object, or array
  • Updated EmailSendOptions type to accept string | IBinaryData | IBinaryData[]
  • Added comprehensive unit tests (12 tests) covering backward compatibility and new expression functionality
  • Maintained full backward compatibility with existing workflows

Summary

Fixes a bug where users cannot use expressions to reference binary data from other nodes in the EmailSend node's attachments parameter. Previously, only comma-separated string property names were supported (e.g., "data, file1"). Now users can also use expressions like ={{ $('Read File').item.binary.data }} to dynamically reference binary data.

What changed

  • Enhanced attachment processing to detect and handle both string and object/array inputs
  • Updated type definitions to accept string | IBinaryData | IBinaryData[]
  • Added comprehensive unit tests (12 tests) covering all scenarios
  • Fully backward compatible - existing workflows continue to work unchanged

How to test

  1. Create a workflow with a node that outputs binary data (e.g., "Read/Write Files from Disk")
  2. Add an EmailSend node
  3. In the attachments field, use an expression: ={{ $('Read/Write Files from Disk').item.binary.data }}
  4. Execute the workflow
  5. Verify that the email is sent with the attachment

Before this fix: Attachment would not be sent (expression resolved to object, code expected string)
After this fix: Attachment is correctly attached to the email

Test Coverage

  • ✅ Backward compatibility with string property names ("data", "data, file1, file2")
  • ✅ Expression-resolved IBinaryData objects
  • ✅ Arrays of binary data objects
  • ✅ All email formats (HTML, text, both)
  • ✅ Edge cases (no attachments, no binary data, whitespace handling)

Related Linear tickets, Github issues, and Community forum posts

Fixes #20832
Linear: https://linear.app/n8n/issue/GHC-5047

Review / Merge checklist

  • PR title and summary are descriptive
  • Docs updated or follow-up ticket created
  • Tests included (12 unit tests)
  • PR Labeled with release/backport (not applicable - this is not an urgent fix)

Additional Notes

Breaking Changes: None - fully backward compatible

Files Changed:

  • packages/nodes-base/nodes/EmailSend/v2/send.operation.ts - Core fix
  • packages/nodes-base/nodes/EmailSend/v2/utils.ts - Type definitions
  • packages/nodes-base/nodes/EmailSend/test/v2/send.operation.test.ts - Test coverage (NEW)

Code Quality:

  • ✅ All tests passing (13/13)
  • ✅ Lint passed
  • ✅ Typecheck passed
  • ✅ No ts-ignore usage
  • ✅ Follows n8n coding conventions

Fixes n8n-io#20832

Users can now use expressions like ={{ $('NodeName').item.binary.data }}
in the attachments parameter, in addition to the existing comma-separated
string format.

Changes:
- Enhanced attachment processing to handle string, IBinaryData object, or array
- Updated EmailSendOptions type to accept string | IBinaryData | IBinaryData[]
- Added comprehensive unit tests (12 tests) covering backward compatibility
  and new expression functionality
- Maintained full backward compatibility with existing workflows
@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@n8n-assistant n8n-assistant bot added community Authored by a community member node/improvement New feature or request in linear Issue or PR has been created in Linear for internal review labels Nov 25, 2025
@n8n-assistant
Copy link

n8n-assistant bot commented Nov 25, 2025

Hey @nsouzaco,

Thank you for your contribution. We appreciate the time and effort you’ve taken to submit this pull request.

Before we can proceed, please ensure the following:
• Tests are included for any new functionality, logic changes or bug fixes.
• The PR aligns with our contribution guidelines.

Regarding new nodes:
We no longer accept new nodes directly into the core codebase. Instead, we encourage contributors to follow our Community Node Submission Guide to publish nodes independently.

If your node integrates with an AI service that you own or represent, please email [email protected] and we will be happy to discuss the best approach.

About review timelines:
This PR has been added to our internal tracker as "GHC-5618". While we plan to review it, we are currently unable to provide an exact timeframe. Our goal is to begin reviews within a month, but this may change depending on team priorities. We will reach out when the review begins.

Thank you again for contributing to n8n.

Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

1 issue found across 3 files

Prompt for AI agents (all 1 issues)

Understand the root cause of the following 1 issues and fix them.


<file name="packages/nodes-base/nodes/EmailSend/v2/send.operation.ts">

<violation number="1" location="packages/nodes-base/nodes/EmailSend/v2/send.operation.ts:240">
Expression-based attachments remain disabled because the new handling only runs when the current item already has binary data; drop the `item.binary` guard so IBinaryData objects returned from expressions are processed.</violation>
</file>

Since this is your first cubic review, here's how it works:

  • cubic automatically reviews your code and comments on bugs and improvements
  • Teach cubic by replying to its comments. cubic learns from your replies and gets better over time
  • Ask questions if you need clarification on any suggestion

Reply to cubic to teach it or ask questions. Re-run a review with @cubic-dev-ai review this PR


for (const propertyName of attachmentProperties) {
const binaryData = this.helpers.assertBinaryData(itemIndex, propertyName);
// Handle both string property names and expression-resolved binary data
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot Nov 25, 2025

Choose a reason for hiding this comment

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

Expression-based attachments remain disabled because the new handling only runs when the current item already has binary data; drop the item.binary guard so IBinaryData objects returned from expressions are processed.

Prompt for AI agents
Address the following comment on packages/nodes-base/nodes/EmailSend/v2/send.operation.ts at line 240:

<comment>Expression-based attachments remain disabled because the new handling only runs when the current item already has binary data; drop the `item.binary` guard so IBinaryData objects returned from expressions are processed.</comment>

<file context>
@@ -235,18 +236,44 @@ export async function execute(this: IExecuteFunctions): Promise&lt;INodeExecutionDa
 
-				for (const propertyName of attachmentProperties) {
-					const binaryData = this.helpers.assertBinaryData(itemIndex, propertyName);
+				// Handle both string property names and expression-resolved binary data
+				let attachmentItems: Array&lt;string | IBinaryData&gt; = [];
+
</file context>
Fix with Cubic

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community Authored by a community member in linear Issue or PR has been created in Linear for internal review node/improvement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Binary property reference doesn't work in Send Email node - no attachment is sent

2 participants