Skip to content
This repository was archived by the owner on Jan 7, 2026. It is now read-only.

Commit 434c91b

Browse files
Handle attachments
1 parent 4d41c04 commit 434c91b

1 file changed

Lines changed: 24 additions & 1 deletion

File tree

email-sender/email-sender.js

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,29 @@ module.exports = function(RED) {
2828
const secure = RED.util.evaluateNodeProperty(config.secure, config.secureType, node, msg);
2929
const rejectUnauthorized = RED.util.evaluateNodeProperty(config.rejectUnauthorized, config.rejectUnauthorizedType, node, msg);
3030

31+
// Handle attachments and format them for Nodemailer
32+
let processedAttachments = [];
33+
if (attachments) {
34+
// Check if it's a single attachment or an array
35+
const attachmentArray = Array.isArray(attachments) ? attachments : [attachments];
36+
37+
for (const attachment of attachmentArray) {
38+
try {
39+
// Assuming the attachment object has a 'filename' and 'content' property
40+
if (attachment.filename && attachment.content) {
41+
processedAttachments.push({
42+
filename: attachment.filename,
43+
content: attachment.content
44+
});
45+
} else {
46+
node.warn("Attachment object is missing 'filename' or 'content' property and will be ignored.");
47+
}
48+
} catch (e) {
49+
node.error("Failed to process attachment: " + e.message);
50+
}
51+
}
52+
}
53+
3154
// Create SMTP transporter
3255
const transporter = nodemailer.createTransport({
3356
host: host,
@@ -53,7 +76,7 @@ module.exports = function(RED) {
5376
bcc: bcc,
5477
subject: subject,
5578
html: Buffer.from(htmlContent, 'utf-8'),
56-
attachments: attachments
79+
attachments: processedAttachments
5780
};
5881

5982
// Send email

0 commit comments

Comments
 (0)