mirror of
https://github.com/n8n-io/n8n.git
synced 2024-12-24 04:04:06 -08:00
⚡ Small improvements to AWS-SES-Node
This commit is contained in:
parent
03c1b0542d
commit
224a51fa56
|
@ -1,4 +1,4 @@
|
||||||
import { IExecuteFunctions, LoadNodeParameterOptions } from 'n8n-core';
|
import { IExecuteFunctions } from 'n8n-core';
|
||||||
import {
|
import {
|
||||||
INodeTypeDescription,
|
INodeTypeDescription,
|
||||||
INodeExecutionData,
|
INodeExecutionData,
|
||||||
|
@ -10,7 +10,7 @@ import { awsApiRequestSOAP } from './GenericFunctions';
|
||||||
|
|
||||||
function setParameter(params: string[], base: string, values: string[]) {
|
function setParameter(params: string[], base: string, values: string[]) {
|
||||||
for (let i = 0; i < values.length; i++) {
|
for (let i = 0; i < values.length; i++) {
|
||||||
params.push(`${base}.${i+1}=${values[i]}`)
|
params.push(`${base}.${i+1}=${values[i]}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,26 +61,7 @@ export class AwsSes implements INodeType {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
default: false,
|
default: false,
|
||||||
description: 'Weather the body is html or not',
|
description: 'If body is HTML or simple text.',
|
||||||
},
|
|
||||||
{
|
|
||||||
displayName: 'Body',
|
|
||||||
name: 'body',
|
|
||||||
type: 'string',
|
|
||||||
typeOptions: {
|
|
||||||
alwaysOpenEditWindow: true,
|
|
||||||
},
|
|
||||||
displayOptions: {
|
|
||||||
show: {
|
|
||||||
operation: [
|
|
||||||
'sendEmail',
|
|
||||||
],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
options: [],
|
|
||||||
default: '',
|
|
||||||
description: 'The message to be sent.',
|
|
||||||
required: true,
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
displayName: 'Subject',
|
displayName: 'Subject',
|
||||||
|
@ -97,8 +78,26 @@ export class AwsSes implements INodeType {
|
||||||
required: true,
|
required: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
displayName: 'Source',
|
displayName: 'Body',
|
||||||
name: 'source',
|
name: 'body',
|
||||||
|
type: 'string',
|
||||||
|
typeOptions: {
|
||||||
|
alwaysOpenEditWindow: true,
|
||||||
|
},
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
operation: [
|
||||||
|
'sendEmail',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
default: '',
|
||||||
|
description: 'The message to be sent.',
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
displayName: 'From Email',
|
||||||
|
name: 'fromEmail',
|
||||||
type: 'string',
|
type: 'string',
|
||||||
displayOptions: {
|
displayOptions: {
|
||||||
show: {
|
show: {
|
||||||
|
@ -108,9 +107,29 @@ export class AwsSes implements INodeType {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
required: true,
|
required: true,
|
||||||
description: 'The email address that is sending the email.',
|
description: 'Email address of the sender.',
|
||||||
|
placeholder: 'admin@example.com',
|
||||||
default: '',
|
default: '',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
displayName: 'To Addresses',
|
||||||
|
name: 'toAddresses',
|
||||||
|
type: 'string',
|
||||||
|
description: 'Email addresses of the recipients.',
|
||||||
|
typeOptions: {
|
||||||
|
multipleValues: true,
|
||||||
|
multipleValueButtonText: 'Add To Email',
|
||||||
|
},
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
operation: [
|
||||||
|
'sendEmail',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
placeholder: 'info@example.com',
|
||||||
|
default: [],
|
||||||
|
},
|
||||||
{
|
{
|
||||||
displayName: 'Additional Fields',
|
displayName: 'Additional Fields',
|
||||||
name: 'additionalFields',
|
name: 'additionalFields',
|
||||||
|
@ -125,18 +144,52 @@ export class AwsSes implements INodeType {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
options: [
|
options: [
|
||||||
|
{
|
||||||
|
displayName: 'Bcc Addresses',
|
||||||
|
name: 'bccAddresses',
|
||||||
|
type: 'string',
|
||||||
|
typeOptions: {
|
||||||
|
multipleValues: true,
|
||||||
|
multipleValueButtonText: 'Add Bcc Email',
|
||||||
|
},
|
||||||
|
description: 'Bcc Recipients of the email.',
|
||||||
|
default: [],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Cc Addresses',
|
||||||
|
name: 'ccAddresses',
|
||||||
|
type: 'string',
|
||||||
|
typeOptions: {
|
||||||
|
multipleValues: true,
|
||||||
|
multipleValueButtonText: 'Add Cc Email',
|
||||||
|
},
|
||||||
|
description: 'Cc recipients of the email.',
|
||||||
|
default: [],
|
||||||
|
},
|
||||||
{
|
{
|
||||||
displayName: 'Configuration Set Name',
|
displayName: 'Configuration Set Name',
|
||||||
name: 'configurationSetName',
|
name: 'configurationSetName',
|
||||||
type: 'string',
|
type: 'string',
|
||||||
description: 'The name of the configuration set to use when you send an email using SendEmail.',
|
description: 'Name of the configuration set to use when you send an email using SendEmail.',
|
||||||
default: '',
|
default: '',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Reply To Addresses',
|
||||||
|
name: 'replyToAddresses',
|
||||||
|
type: 'string',
|
||||||
|
typeOptions: {
|
||||||
|
multipleValues: true,
|
||||||
|
multipleValueButtonText: 'Add Reply To Email',
|
||||||
|
},
|
||||||
|
placeholder: 'Add Reply Address',
|
||||||
|
description: 'Reply-to email address(es) for the message.',
|
||||||
|
default: [],
|
||||||
|
},
|
||||||
{
|
{
|
||||||
displayName: 'Return Path',
|
displayName: 'Return Path',
|
||||||
name: 'returnPath',
|
name: 'returnPath',
|
||||||
type: 'string',
|
type: 'string',
|
||||||
description: 'The email address that bounces and complaints will be forwarded to when feedback forwarding is enabled',
|
description: 'Email address that bounces and complaints will be forwarded to when feedback forwarding is enabled',
|
||||||
default: '',
|
default: '',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -153,113 +206,6 @@ export class AwsSes implements INodeType {
|
||||||
description: 'This parameter is used only for sending authorization.',
|
description: 'This parameter is used only for sending authorization.',
|
||||||
default: '',
|
default: '',
|
||||||
},
|
},
|
||||||
{
|
|
||||||
displayName: 'Reply To Addresses',
|
|
||||||
name: 'replyToAddressesUI',
|
|
||||||
type: 'fixedCollection',
|
|
||||||
typeOptions: {
|
|
||||||
multipleValues: true,
|
|
||||||
},
|
|
||||||
placeholder: 'Add Reply Address',
|
|
||||||
description: 'The reply-to email address(es) for the message.',
|
|
||||||
default: {},
|
|
||||||
options: [
|
|
||||||
{
|
|
||||||
displayName: 'Reply Address',
|
|
||||||
name: 'replyToAddressesValues',
|
|
||||||
values: [
|
|
||||||
{
|
|
||||||
displayName: 'Address',
|
|
||||||
name: 'address',
|
|
||||||
type: 'string',
|
|
||||||
default: '',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
displayName: 'Cc Addresses',
|
|
||||||
name: 'ccAddressesUi',
|
|
||||||
type: 'fixedCollection',
|
|
||||||
typeOptions: {
|
|
||||||
multipleValues: true,
|
|
||||||
},
|
|
||||||
placeholder: 'Add Cc Address',
|
|
||||||
description: 'The recipients to place on the CC: line of the message.',
|
|
||||||
default: {},
|
|
||||||
options: [
|
|
||||||
{
|
|
||||||
displayName: 'Cc Address',
|
|
||||||
name: 'ccAddressesValues',
|
|
||||||
values: [
|
|
||||||
{
|
|
||||||
displayName: 'Address',
|
|
||||||
name: 'address',
|
|
||||||
type: 'string',
|
|
||||||
default: '',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
displayName: 'Bcc Addresses',
|
|
||||||
name: 'bccAddressesUi',
|
|
||||||
type: 'fixedCollection',
|
|
||||||
typeOptions: {
|
|
||||||
multipleValues: true,
|
|
||||||
},
|
|
||||||
placeholder: 'Add CC Address',
|
|
||||||
description: 'The recipients to place on the BCC: line of the message.',
|
|
||||||
default: {},
|
|
||||||
options: [
|
|
||||||
{
|
|
||||||
displayName: 'Bcc Address',
|
|
||||||
name: 'bccAddressesValues',
|
|
||||||
values: [
|
|
||||||
{
|
|
||||||
displayName: 'Address',
|
|
||||||
name: 'address',
|
|
||||||
type: 'string',
|
|
||||||
default: '',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
displayName: 'To Addresses',
|
|
||||||
name: 'toAddressesUi',
|
|
||||||
type: 'fixedCollection',
|
|
||||||
description: 'The recipients to place on the To: line of the message.',
|
|
||||||
typeOptions: {
|
|
||||||
multipleValues: true,
|
|
||||||
},
|
|
||||||
displayOptions: {
|
|
||||||
show: {
|
|
||||||
operation: [
|
|
||||||
'sendEmail',
|
|
||||||
],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
placeholder: 'Add Address',
|
|
||||||
default: {},
|
|
||||||
options: [
|
|
||||||
{
|
|
||||||
displayName: 'Address',
|
|
||||||
name: 'toAddressesValues',
|
|
||||||
values: [
|
|
||||||
{
|
|
||||||
displayName: 'Address',
|
|
||||||
name: 'address',
|
|
||||||
type: 'string',
|
|
||||||
default: '',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
@ -268,30 +214,29 @@ export class AwsSes implements INodeType {
|
||||||
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
|
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
|
||||||
const items = this.getInputData();
|
const items = this.getInputData();
|
||||||
const returnData: IDataObject[] = [];
|
const returnData: IDataObject[] = [];
|
||||||
const length = items.length as unknown as number;
|
|
||||||
let responseData;
|
let responseData;
|
||||||
const operation = this.getNodeParameter('operation', 0) as string;
|
const operation = this.getNodeParameter('operation', 0) as string;
|
||||||
for (let i = 0; i < length; i++) {
|
for (let i = 0; i < items.length; i++) {
|
||||||
if (operation === 'sendEmail') {
|
if (operation === 'sendEmail') {
|
||||||
let toAddresses = (this.getNodeParameter('toAddressesUi', i) as IDataObject).toAddressesValues as string[];
|
const toAddresses = this.getNodeParameter('toAddresses', i) as string[];
|
||||||
const message = this.getNodeParameter('body', i) as string;
|
const message = this.getNodeParameter('body', i) as string;
|
||||||
const subject = this.getNodeParameter('subject', i) as string;
|
const subject = this.getNodeParameter('subject', i) as string;
|
||||||
const source = this.getNodeParameter('source', i) as string;
|
const fromEmail = this.getNodeParameter('fromEmail', i) as string;
|
||||||
const isBodyHtml = this.getNodeParameter('isBodyHtml', i) as boolean;
|
const isBodyHtml = this.getNodeParameter('isBodyHtml', i) as boolean;
|
||||||
const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
|
const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
|
||||||
const params = [
|
const params = [
|
||||||
`Message.Subject.Data=${subject}`,
|
`Message.Subject.Data=${subject}`,
|
||||||
`Source=${source}`,
|
`Source=${fromEmail}`,
|
||||||
];
|
];
|
||||||
if (isBodyHtml) {
|
if (isBodyHtml) {
|
||||||
params.push(`Message.Body.Html.Data=${message}`);
|
params.push(`Message.Body.Html.Data=${message}`);
|
||||||
} else {
|
} else {
|
||||||
params.push(`Message.Body.Text.Data=${message}`);
|
params.push(`Message.Body.Text.Data=${message}`);
|
||||||
}
|
}
|
||||||
if (toAddresses) {
|
if (toAddresses.length) {
|
||||||
//@ts-ignore
|
|
||||||
toAddresses = toAddresses.map(o => o.address);
|
|
||||||
setParameter(params, 'Destination.ToAddresses.member', toAddresses);
|
setParameter(params, 'Destination.ToAddresses.member', toAddresses);
|
||||||
|
} else {
|
||||||
|
throw new Error('At least one "To Address" has to be added!');
|
||||||
}
|
}
|
||||||
if (additionalFields.configurationSetName) {
|
if (additionalFields.configurationSetName) {
|
||||||
params.push(`ConfigurationSetName=${additionalFields.configurationSetName}`);
|
params.push(`ConfigurationSetName=${additionalFields.configurationSetName}`);
|
||||||
|
@ -305,21 +250,11 @@ export class AwsSes implements INodeType {
|
||||||
if (additionalFields.sourceArn) {
|
if (additionalFields.sourceArn) {
|
||||||
params.push(`SourceArn=${additionalFields.sourceArn}`);
|
params.push(`SourceArn=${additionalFields.sourceArn}`);
|
||||||
}
|
}
|
||||||
if (additionalFields.replyToAddressesUI) {
|
if (additionalFields.replyToAddresses) {
|
||||||
let replyToAddresses = (additionalFields.replyToAddressesUI as IDataObject).replyToAddressesValues as string[];
|
setParameter(params, 'ReplyToAddresses.member', additionalFields.replyToAddresses as string[]);
|
||||||
//@ts-ignore
|
|
||||||
replyToAddresses = replyToAddresses.map(o => o.address);
|
|
||||||
if (replyToAddresses) {
|
|
||||||
setParameter(params, 'ReplyToAddresses.member', replyToAddresses);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (additionalFields.bccAddressesUi) {
|
if (additionalFields.bccAddresses) {
|
||||||
let bccAddresses = (additionalFields.bccAddressesUi as IDataObject).bccAddressesValues as string[];
|
setParameter(params, 'Destination.BccAddresses.member', additionalFields.bccAddresses as string[]);
|
||||||
//@ts-ignore
|
|
||||||
bccAddresses = bccAddresses.map(o => o.address);
|
|
||||||
if (bccAddresses) {
|
|
||||||
setParameter(params, 'Destination.BccAddresses.member', bccAddresses);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (additionalFields.ccAddressesUi) {
|
if (additionalFields.ccAddressesUi) {
|
||||||
let ccAddresses = (additionalFields.ccAddressesUi as IDataObject).ccAddressesValues as string[];
|
let ccAddresses = (additionalFields.ccAddressesUi as IDataObject).ccAddressesValues as string[];
|
||||||
|
@ -329,6 +264,7 @@ export class AwsSes implements INodeType {
|
||||||
setParameter(params, 'Destination.CcAddresses.member', ccAddresses);
|
setParameter(params, 'Destination.CcAddresses.member', ccAddresses);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
responseData = await awsApiRequestSOAP.call(this, 'email', 'POST', '/?Action=SendEmail&' + params.join('&'));
|
responseData = await awsApiRequestSOAP.call(this, 'email', 'POST', '/?Action=SendEmail&' + params.join('&'));
|
||||||
} catch(err) {
|
} catch(err) {
|
||||||
|
|
|
@ -31,9 +31,8 @@ export async function awsApiRequest(this: IHookFunctions | IExecuteFunctions | I
|
||||||
try {
|
try {
|
||||||
return await this.helpers.request!(options);
|
return await this.helpers.request!(options);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
//console.error(error);
|
const errorMessage = error.response.body.message || error.response.body.Message || error.message;
|
||||||
|
|
||||||
const errorMessage = error.response.body.message || error.response.body.Message;
|
|
||||||
if (error.statusCode === 403) {
|
if (error.statusCode === 403) {
|
||||||
if (errorMessage === 'The security token included in the request is invalid.') {
|
if (errorMessage === 'The security token included in the request is invalid.') {
|
||||||
throw new Error('The AWS credentials are not valid!');
|
throw new Error('The AWS credentials are not valid!');
|
||||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 2.5 KiB After Width: | Height: | Size: 1,022 B |
|
@ -105,8 +105,8 @@
|
||||||
"dist/nodes/Asana/Asana.node.js",
|
"dist/nodes/Asana/Asana.node.js",
|
||||||
"dist/nodes/Asana/AsanaTrigger.node.js",
|
"dist/nodes/Asana/AsanaTrigger.node.js",
|
||||||
"dist/nodes/Aws/AwsLambda.node.js",
|
"dist/nodes/Aws/AwsLambda.node.js",
|
||||||
"dist/nodes/Aws/AwsSns.node.js",
|
|
||||||
"dist/nodes/Aws/AwsSes.node.js",
|
"dist/nodes/Aws/AwsSes.node.js",
|
||||||
|
"dist/nodes/Aws/AwsSns.node.js",
|
||||||
"dist/nodes/Bitbucket/BitbucketTrigger.node.js",
|
"dist/nodes/Bitbucket/BitbucketTrigger.node.js",
|
||||||
"dist/nodes/Bitly/Bitly.node.js",
|
"dist/nodes/Bitly/Bitly.node.js",
|
||||||
"dist/nodes/Chargebee/Chargebee.node.js",
|
"dist/nodes/Chargebee/Chargebee.node.js",
|
||||||
|
|
Loading…
Reference in a new issue