feat: Support inline attachments in SendGrid node

This commit is contained in:
Denis Perov 2024-10-11 09:04:40 +03:00
parent 1078fa662a
commit 4baa51c4a4
3 changed files with 62 additions and 9 deletions

View file

@ -209,9 +209,54 @@ export const mailFields: INodeProperties[] = [
{
displayName: 'Attachments',
name: 'attachments',
type: 'fixedCollection',
typeOptions: {
multipleValues: true,
},
default: {},
options: [
{
displayName: 'Attachment',
name: 'data',
values: [
{
displayName: 'Property',
name: 'property',
type: 'string',
default: 'data',
description: 'Binary property name',
},
{
displayName: 'Content Disposition',
name: 'disposition',
type: 'options',
default: 'attachment',
options: [
{
name: 'Attachment',
value: 'attachment',
},
{
name: 'Inline',
value: 'inline',
},
],
description:
"The attachment's content-disposition specifies how you would like the attachment to be displayed",
},
{
displayName: 'Content ID',
name: 'contentId',
type: 'string',
default: '',
description: 'Comma-separated list of binary properties',
description:
'The attachment\'s Content ID is used when the Disposition is set to "inline" and the attachment is an image, allowing the file to be displayed within the body of the email',
hint: 'Default to "attachmentN", where N is the attachment\'s index (zero-based)',
},
],
},
],
description: 'File attachments',
},
{
displayName: 'BCC Email',

View file

@ -1,7 +1,7 @@
{
"node": "n8n-nodes-base.sendGrid",
"nodeVersion": "1.0",
"codexVersion": "1.0",
"nodeVersion": "1.1",
"codexVersion": "1.1",
"categories": ["Marketing", "Communication"],
"resources": {
"credentialDocumentation": [

View file

@ -532,7 +532,13 @@ export class SendGrid implements INodeType {
enableSandbox: boolean;
sendAt: string;
headers: { details: Array<{ key: string; value: string }> };
attachments: string;
attachments: {
data: {
property: string;
disposition: 'attachment' | 'inline';
contentId: string;
}[];
};
categories: string;
ipPoolName: string;
};
@ -582,11 +588,11 @@ export class SendGrid implements INodeType {
];
}
if (attachments) {
if (attachments?.data) {
const attachmentsToSend = [];
const binaryProperties = attachments.split(',').map((p) => p.trim());
for (const property of binaryProperties) {
for (const ai in attachments.data) {
const { property, disposition, contentId } = attachments.data[ai];
const binaryData = this.helpers.assertBinaryData(i, property);
const dataBuffer = await this.helpers.getBinaryDataBuffer(i, property);
@ -594,6 +600,8 @@ export class SendGrid implements INodeType {
content: dataBuffer.toString('base64'),
filename: binaryData.fileName || 'unknown',
type: binaryData.mimeType,
disposition,
content_id: contentId || `attachment${ai}`,
});
}