mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -08:00
feat: Support inline attachments in SendGrid node
This commit is contained in:
parent
1078fa662a
commit
4baa51c4a4
|
@ -209,9 +209,54 @@ export const mailFields: INodeProperties[] = [
|
||||||
{
|
{
|
||||||
displayName: 'Attachments',
|
displayName: 'Attachments',
|
||||||
name: 'attachments',
|
name: 'attachments',
|
||||||
type: 'string',
|
type: 'fixedCollection',
|
||||||
default: '',
|
typeOptions: {
|
||||||
description: 'Comma-separated list of binary properties',
|
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:
|
||||||
|
'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',
|
displayName: 'BCC Email',
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"node": "n8n-nodes-base.sendGrid",
|
"node": "n8n-nodes-base.sendGrid",
|
||||||
"nodeVersion": "1.0",
|
"nodeVersion": "1.1",
|
||||||
"codexVersion": "1.0",
|
"codexVersion": "1.1",
|
||||||
"categories": ["Marketing", "Communication"],
|
"categories": ["Marketing", "Communication"],
|
||||||
"resources": {
|
"resources": {
|
||||||
"credentialDocumentation": [
|
"credentialDocumentation": [
|
||||||
|
|
|
@ -532,7 +532,13 @@ export class SendGrid implements INodeType {
|
||||||
enableSandbox: boolean;
|
enableSandbox: boolean;
|
||||||
sendAt: string;
|
sendAt: string;
|
||||||
headers: { details: Array<{ key: string; value: string }> };
|
headers: { details: Array<{ key: string; value: string }> };
|
||||||
attachments: string;
|
attachments: {
|
||||||
|
data: {
|
||||||
|
property: string;
|
||||||
|
disposition: 'attachment' | 'inline';
|
||||||
|
contentId: string;
|
||||||
|
}[];
|
||||||
|
};
|
||||||
categories: string;
|
categories: string;
|
||||||
ipPoolName: string;
|
ipPoolName: string;
|
||||||
};
|
};
|
||||||
|
@ -582,11 +588,11 @@ export class SendGrid implements INodeType {
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (attachments) {
|
if (attachments?.data) {
|
||||||
const attachmentsToSend = [];
|
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 binaryData = this.helpers.assertBinaryData(i, property);
|
||||||
const dataBuffer = await this.helpers.getBinaryDataBuffer(i, property);
|
const dataBuffer = await this.helpers.getBinaryDataBuffer(i, property);
|
||||||
|
|
||||||
|
@ -594,6 +600,8 @@ export class SendGrid implements INodeType {
|
||||||
content: dataBuffer.toString('base64'),
|
content: dataBuffer.toString('base64'),
|
||||||
filename: binaryData.fileName || 'unknown',
|
filename: binaryData.fileName || 'unknown',
|
||||||
type: binaryData.mimeType,
|
type: binaryData.mimeType,
|
||||||
|
disposition,
|
||||||
|
content_id: contentId || `attachment${ai}`,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue