mirror of
https://github.com/n8n-io/n8n.git
synced 2024-12-25 20:54:07 -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 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 credentials = this.getCredentials('mailgunApi');
|
for (let itemIndex = 0; itemIndex < length; itemIndex++) {
|
||||||
|
item = items[itemIndex];
|
||||||
|
|
||||||
if (credentials === undefined) {
|
const fromEmail = this.getNodeParameter('fromEmail', itemIndex) as string;
|
||||||
throw new Error('No credentials got returned!');
|
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 formData: IDataObject = {
|
const credentials = this.getCredentials('mailgunApi');
|
||||||
from: fromEmail,
|
|
||||||
to: toEmail,
|
|
||||||
subject,
|
|
||||||
text,
|
|
||||||
html,
|
|
||||||
};
|
|
||||||
|
|
||||||
if (ccEmail.length !== 0) {
|
if (credentials === undefined) {
|
||||||
formData.cc = ccEmail;
|
throw new Error('No credentials got returned!');
|
||||||
}
|
}
|
||||||
if (bccEmail.length !== 0) {
|
|
||||||
formData.bcc = bccEmail;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (attachmentPropertyString && item.binary) {
|
const formData: IDataObject = {
|
||||||
|
from: fromEmail,
|
||||||
|
to: toEmail,
|
||||||
|
subject,
|
||||||
|
text,
|
||||||
|
html,
|
||||||
|
};
|
||||||
|
|
||||||
const attachments = [];
|
if (ccEmail.length !== 0) {
|
||||||
const attachmentProperties: string[] = attachmentPropertyString.split(',').map((propertyName) => {
|
formData.cc = ccEmail;
|
||||||
return propertyName.trim();
|
}
|
||||||
});
|
if (bccEmail.length !== 0) {
|
||||||
|
formData.bcc = bccEmail;
|
||||||
|
}
|
||||||
|
|
||||||
for (const propertyName of attachmentProperties) {
|
if (attachmentPropertyString && item.binary) {
|
||||||
if (!item.binary.hasOwnProperty(propertyName)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
attachments.push({
|
|
||||||
value: Buffer.from(item.binary[propertyName].data, BINARY_ENCODING),
|
|
||||||
options: {
|
|
||||||
filename: item.binary[propertyName].fileName || 'unknown',
|
|
||||||
|
|
||||||
},
|
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({
|
||||||
|
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 responseData = await this.helpers.request(options);
|
||||||
|
|
||||||
|
returnData.push({
|
||||||
|
json: responseData,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
return this.prepareOutputData(returnData)
|
||||||
const 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);
|
|
||||||
|
|
||||||
return {
|
|
||||||
json: responseData,
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue