mirror of
https://github.com/n8n-io/n8n.git
synced 2024-12-25 04:34:06 -08:00
Remove executeSingle from Mailgun node
This commit is contained in:
parent
81f33b4c04
commit
5cce827d6f
|
@ -1,6 +1,6 @@
|
||||||
import {
|
import {
|
||||||
BINARY_ENCODING,
|
BINARY_ENCODING,
|
||||||
IExecuteSingleFunctions,
|
IExecuteFunctions,
|
||||||
} from 'n8n-core';
|
} from 'n8n-core';
|
||||||
import {
|
import {
|
||||||
IDataObject,
|
IDataObject,
|
||||||
|
@ -105,80 +105,89 @@ export class Mailgun implements INodeType {
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
async executeSingle(this: IExecuteSingleFunctions): Promise<INodeExecutionData> {
|
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
|
||||||
const item = this.getInputData();
|
const items = this.getInputData();
|
||||||
|
|
||||||
|
const returnData: INodeExecutionData[] = [];
|
||||||
|
const length = items.length as unknown as number;
|
||||||
|
let item: INodeExecutionData;
|
||||||
|
|
||||||
const fromEmail = this.getNodeParameter('fromEmail') as string;
|
for (let itemIndex = 0; itemIndex < length; itemIndex++) {
|
||||||
const toEmail = this.getNodeParameter('toEmail') as string;
|
item = items[itemIndex];
|
||||||
const ccEmail = this.getNodeParameter('ccEmail') as string;
|
|
||||||
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 credentials = this.getCredentials('mailgunApi');
|
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;
|
||||||
|
|
||||||
if (credentials === undefined) {
|
const credentials = this.getCredentials('mailgunApi');
|
||||||
throw new Error('No credentials got returned!');
|
|
||||||
}
|
|
||||||
|
|
||||||
const formData: IDataObject = {
|
if (credentials === undefined) {
|
||||||
from: fromEmail,
|
throw new Error('No credentials got returned!');
|
||||||
to: toEmail,
|
}
|
||||||
subject,
|
|
||||||
text,
|
|
||||||
html,
|
|
||||||
};
|
|
||||||
|
|
||||||
if (ccEmail.length !== 0) {
|
const formData: IDataObject = {
|
||||||
formData.cc = ccEmail;
|
from: fromEmail,
|
||||||
}
|
to: toEmail,
|
||||||
if (bccEmail.length !== 0) {
|
subject,
|
||||||
formData.bcc = bccEmail;
|
text,
|
||||||
}
|
html,
|
||||||
|
};
|
||||||
|
|
||||||
if (attachmentPropertyString && item.binary) {
|
if (ccEmail.length !== 0) {
|
||||||
|
formData.cc = ccEmail;
|
||||||
|
}
|
||||||
|
if (bccEmail.length !== 0) {
|
||||||
|
formData.bcc = bccEmail;
|
||||||
|
}
|
||||||
|
|
||||||
const attachments = [];
|
if (attachmentPropertyString && item.binary) {
|
||||||
const attachmentProperties: string[] = attachmentPropertyString.split(',').map((propertyName) => {
|
|
||||||
return propertyName.trim();
|
|
||||||
});
|
|
||||||
|
|
||||||
for (const propertyName of attachmentProperties) {
|
const attachments = [];
|
||||||
if (!item.binary.hasOwnProperty(propertyName)) {
|
const attachmentProperties: string[] = attachmentPropertyString.split(',').map((propertyName) => {
|
||||||
continue;
|
return propertyName.trim();
|
||||||
}
|
|
||||||
attachments.push({
|
|
||||||
value: Buffer.from(item.binary[propertyName].data, BINARY_ENCODING),
|
|
||||||
options: {
|
|
||||||
filename: item.binary[propertyName].fileName || 'unknown',
|
|
||||||
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
for (const propertyName of attachmentProperties) {
|
||||||
|
if (!item.binary.hasOwnProperty(propertyName)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
attachments.push({
|
||||||
|
value: Buffer.from(item.binary[propertyName].data, BINARY_ENCODING),
|
||||||
|
options: {
|
||||||
|
filename: item.binary[propertyName].fileName || 'unknown',
|
||||||
|
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (attachments.length) {
|
||||||
|
// @ts-ignore
|
||||||
|
formData.attachment = attachments;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (attachments.length) {
|
const options = {
|
||||||
// @ts-ignore
|
method: 'POST',
|
||||||
formData.attachment = attachments;
|
formData,
|
||||||
}
|
uri: `https://${credentials.apiDomain}/v3/${credentials.emailDomain}/messages`,
|
||||||
}
|
auth: {
|
||||||
|
user: 'api',
|
||||||
|
pass: credentials.apiKey as string,
|
||||||
|
},
|
||||||
|
json: true,
|
||||||
|
};
|
||||||
|
|
||||||
const options = {
|
const responseData = await this.helpers.request(options);
|
||||||
method: 'POST',
|
|
||||||
formData,
|
|
||||||
uri: `https://${credentials.apiDomain}/v3/${credentials.emailDomain}/messages`,
|
|
||||||
auth: {
|
|
||||||
user: 'api',
|
|
||||||
pass: credentials.apiKey as string,
|
|
||||||
},
|
|
||||||
json: true,
|
|
||||||
};
|
|
||||||
|
|
||||||
const responseData = await this.helpers.request(options);
|
returnData.push({
|
||||||
|
json: responseData,
|
||||||
return {
|
});
|
||||||
json: responseData,
|
}
|
||||||
};
|
return this.prepareOutputData(returnData)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue