mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -08:00
Remove executeSingle from EmailSend node
This commit is contained in:
parent
caad6d1c8d
commit
46d1a5fe58
|
@ -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++) {
|
||||||
|
|
||||||
if (credentials === undefined) {
|
item = items[itemIndex];
|
||||||
throw new Error('No credentials got returned!');
|
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;
|
||||||
|
|
||||||
const connectionOptions: SMTPTransport.Options = {
|
const credentials = this.getCredentials('smtp');
|
||||||
host: credentials.host as string,
|
|
||||||
port: credentials.port as number,
|
|
||||||
secure: credentials.secure as boolean,
|
|
||||||
};
|
|
||||||
|
|
||||||
if(credentials.user || credentials.password) {
|
if (credentials === undefined) {
|
||||||
// @ts-ignore
|
throw new Error('No credentials got returned!');
|
||||||
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 };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue