Remove executeSingle from EmailSend node

This commit is contained in:
dali 2021-02-16 07:23:37 +01:00
parent caad6d1c8d
commit 46d1a5fe58

View file

@ -1,6 +1,6 @@
import { import {
BINARY_ENCODING, BINARY_ENCODING,
IExecuteSingleFunctions, IExecuteFunctions
} from 'n8n-core'; } from 'n8n-core';
import { import {
IDataObject, IDataObject,
@ -124,84 +124,95 @@ export class EmailSend implements INodeType {
}; };
async executeSingle(this: IExecuteSingleFunctions): Promise<INodeExecutionData> { async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
const item = this.getInputData(); const items = this.getInputData();
const fromEmail = this.getNodeParameter('fromEmail') as string; const returnData: INodeExecutionData[] = [];
const toEmail = this.getNodeParameter('toEmail') as string; const length = items.length as unknown as number;
const ccEmail = this.getNodeParameter('ccEmail') as string; let item: INodeExecutionData;
const bccEmail = this.getNodeParameter('bccEmail') as string;
const subject = this.getNodeParameter('subject') as string;
const text = this.getNodeParameter('text') as string;
const html = this.getNodeParameter('html') as string;
const attachmentPropertyString = this.getNodeParameter('attachments') as string;
const options = this.getNodeParameter('options', {}) as IDataObject;
const credentials = this.getCredentials('smtp'); for (let itemIndex = 0; itemIndex < length; itemIndex++) {
item = items[itemIndex];
console.log(item,itemIndex)
const fromEmail = this.getNodeParameter('fromEmail', itemIndex) as string;
const toEmail = this.getNodeParameter('toEmail', itemIndex) as string;
const ccEmail = this.getNodeParameter('ccEmail', itemIndex) as string;
const bccEmail = this.getNodeParameter('bccEmail', itemIndex) as string;
const subject = this.getNodeParameter('subject', itemIndex) as string;
const text = this.getNodeParameter('text', itemIndex) as string;
const html = this.getNodeParameter('html', itemIndex) as string;
const attachmentPropertyString = this.getNodeParameter('attachments', itemIndex) as string;
const options = this.getNodeParameter('options', itemIndex, {}) as IDataObject;
if (credentials === undefined) { const credentials = this.getCredentials('smtp');
throw new Error('No credentials got returned!');
}
const connectionOptions: SMTPTransport.Options = { if (credentials === undefined) {
host: credentials.host as string, throw new Error('No credentials got returned!');
port: credentials.port as number,
secure: credentials.secure as boolean,
};
if(credentials.user || credentials.password) {
// @ts-ignore
connectionOptions.auth = {
user: credentials.user as string,
pass: credentials.password as string,
};
}
if (options.allowUnauthorizedCerts === true) {
connectionOptions.tls = {
rejectUnauthorized: false,
};
}
const transporter = createTransport(connectionOptions);
// setup email data with unicode symbols
const mailOptions = {
from: fromEmail,
to: toEmail,
cc: ccEmail,
bcc: bccEmail,
subject,
text,
html,
};
if (attachmentPropertyString && item.binary) {
const attachments = [];
const attachmentProperties: string[] = attachmentPropertyString.split(',').map((propertyName) => {
return propertyName.trim();
});
for (const propertyName of attachmentProperties) {
if (!item.binary.hasOwnProperty(propertyName)) {
continue;
}
attachments.push({
filename: item.binary[propertyName].fileName || 'unknown',
content: Buffer.from(item.binary[propertyName].data, BINARY_ENCODING),
});
} }
if (attachments.length) { const connectionOptions: SMTPTransport.Options = {
host: credentials.host as string,
port: credentials.port as number,
secure: credentials.secure as boolean,
};
if(credentials.user || credentials.password) {
// @ts-ignore // @ts-ignore
mailOptions.attachments = attachments; connectionOptions.auth = {
user: credentials.user as string,
pass: credentials.password as string,
};
} }
if (options.allowUnauthorizedCerts === true) {
connectionOptions.tls = {
rejectUnauthorized: false,
};
}
const transporter = createTransport(connectionOptions);
// setup email data with unicode symbols
const mailOptions = {
from: fromEmail,
to: toEmail,
cc: ccEmail,
bcc: bccEmail,
subject,
text,
html,
};
if (attachmentPropertyString && item.binary) {
const attachments = [];
const attachmentProperties: string[] = attachmentPropertyString.split(',').map((propertyName) => {
return propertyName.trim();
});
for (const propertyName of attachmentProperties) {
if (!item.binary.hasOwnProperty(propertyName)) {
continue;
}
attachments.push({
filename: item.binary[propertyName].fileName || 'unknown',
content: Buffer.from(item.binary[propertyName].data, BINARY_ENCODING),
});
}
if (attachments.length) {
// @ts-ignore
mailOptions.attachments = attachments;
}
}
// Send the email
const info = await transporter.sendMail(mailOptions);
returnData.push({ json: info });
} }
// Send the email return this.prepareOutputData(returnData);
const info = await transporter.sendMail(mailOptions);
return { json: info };
} }
} }