diff --git a/packages/nodes-base/nodes/Aws/AwsSes.node.ts b/packages/nodes-base/nodes/Aws/AwsSes.node.ts new file mode 100644 index 000000000..74870cc90 --- /dev/null +++ b/packages/nodes-base/nodes/Aws/AwsSes.node.ts @@ -0,0 +1,282 @@ +import { IExecuteFunctions } from 'n8n-core'; +import { + INodeTypeDescription, + INodeExecutionData, + INodeType, + IDataObject +} from 'n8n-workflow'; + +import { awsApiRequestSOAP } from './GenericFunctions'; + +function setParameter(params: string[], base: string, values: string[]) { + for (let i = 0; i < values.length; i++) { + params.push(`${base}.${i+1}=${values[i]}`); + } +} + +export class AwsSes implements INodeType { + description: INodeTypeDescription = { + displayName: 'AWS SES', + name: 'awsSes', + icon: 'file:ses.png', + group: ['output'], + version: 1, + subtitle: '={{$parameter["operation"]}}', + description: 'Sends data to AWS SES', + defaults: { + name: 'AWS SES', + color: '#FF9900', + }, + inputs: ['main'], + outputs: ['main'], + credentials: [ + { + name: 'aws', + required: true, + } + ], + properties: [ + { + displayName: 'Operation', + name: 'operation', + type: 'options', + options: [ + { + name: 'Send Email', + value: 'sendEmail', + }, + ], + default: 'sendEmail', + description: 'The operation to perform.', + }, + { + displayName: 'Is Body HTML', + name: 'isBodyHtml', + type: 'boolean', + displayOptions: { + show: { + operation: [ + 'sendEmail', + ], + }, + }, + default: false, + description: 'If body is HTML or simple text.', + }, + { + displayName: 'Subject', + name: 'subject', + type: 'string', + displayOptions: { + show: { + operation: [ + 'sendEmail', + ], + }, + }, + default: '', + required: true, + }, + { + displayName: 'Body', + 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', + displayOptions: { + show: { + operation: [ + 'sendEmail', + ], + }, + }, + required: true, + description: 'Email address of the sender.', + placeholder: 'admin@example.com', + 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', + name: 'additionalFields', + type: 'collection', + placeholder: 'Add Field', + default: {}, + displayOptions: { + show: { + operation: [ + 'sendEmail', + ], + }, + }, + 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', + name: 'configurationSetName', + type: 'string', + description: 'Name of the configuration set to use when you send an email using SendEmail.', + 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', + name: 'returnPath', + type: 'string', + description: 'Email address that bounces and complaints will be forwarded to when feedback forwarding is enabled', + default: '', + }, + { + displayName: 'Return Path Arn', + name: 'returnPathArn', + type: 'string', + default: '', + description: 'This parameter is used only for sending authorization', + }, + { + displayName: 'Source Arn', + name: 'sourceArn', + type: 'string', + description: 'This parameter is used only for sending authorization.', + default: '', + }, + ], + }, + ], + }; + + async execute(this: IExecuteFunctions): Promise { + const items = this.getInputData(); + const returnData: IDataObject[] = []; + let responseData; + const operation = this.getNodeParameter('operation', 0) as string; + for (let i = 0; i < items.length; i++) { + if (operation === 'sendEmail') { + const toAddresses = this.getNodeParameter('toAddresses', i) as string[]; + const message = this.getNodeParameter('body', i) as string; + const subject = this.getNodeParameter('subject', i) as string; + const fromEmail = this.getNodeParameter('fromEmail', i) as string; + const isBodyHtml = this.getNodeParameter('isBodyHtml', i) as boolean; + const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject; + const params = [ + `Message.Subject.Data=${subject}`, + `Source=${fromEmail}`, + ]; + if (isBodyHtml) { + params.push(`Message.Body.Html.Data=${message}`); + } else { + params.push(`Message.Body.Text.Data=${message}`); + } + if (toAddresses.length) { + setParameter(params, 'Destination.ToAddresses.member', toAddresses); + } else { + throw new Error('At least one "To Address" has to be added!'); + } + if (additionalFields.configurationSetName) { + params.push(`ConfigurationSetName=${additionalFields.configurationSetName}`); + } + if (additionalFields.returnPath) { + params.push(`ReturnPath=${additionalFields.returnPath}`); + } + if (additionalFields.returnPathArn) { + params.push(`ReturnPathArn=${additionalFields.returnPathArn}`); + } + if (additionalFields.sourceArn) { + params.push(`SourceArn=${additionalFields.sourceArn}`); + } + if (additionalFields.replyToAddresses) { + setParameter(params, 'ReplyToAddresses.member', additionalFields.replyToAddresses as string[]); + } + if (additionalFields.bccAddresses) { + setParameter(params, 'Destination.BccAddresses.member', additionalFields.bccAddresses as string[]); + } + if (additionalFields.ccAddressesUi) { + let ccAddresses = (additionalFields.ccAddressesUi as IDataObject).ccAddressesValues as string[]; + //@ts-ignore + ccAddresses = ccAddresses.map(o => o.address); + if (ccAddresses) { + setParameter(params, 'Destination.CcAddresses.member', ccAddresses); + } + } + + try { + responseData = await awsApiRequestSOAP.call(this, 'email', 'POST', '/?Action=SendEmail&' + params.join('&')); + } catch(err) { + throw new Error(err); + } + } + if (Array.isArray(responseData)) { + returnData.push.apply(returnData, responseData as IDataObject[]); + } else { + returnData.push(responseData as IDataObject); + } + } + return [this.helpers.returnJsonArray(returnData)]; + } +} diff --git a/packages/nodes-base/nodes/Aws/GenericFunctions.ts b/packages/nodes-base/nodes/Aws/GenericFunctions.ts index 770d4cfa7..303a02707 100644 --- a/packages/nodes-base/nodes/Aws/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Aws/GenericFunctions.ts @@ -31,9 +31,8 @@ export async function awsApiRequest(this: IHookFunctions | IExecuteFunctions | I try { return await this.helpers.request!(options); } 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 (errorMessage === 'The security token included in the request is invalid.') { throw new Error('The AWS credentials are not valid!'); diff --git a/packages/nodes-base/nodes/Aws/ses.png b/packages/nodes-base/nodes/Aws/ses.png new file mode 100644 index 000000000..d4b396df8 Binary files /dev/null and b/packages/nodes-base/nodes/Aws/ses.png differ diff --git a/packages/nodes-base/package.json b/packages/nodes-base/package.json index 2838e8657..a1a31e472 100644 --- a/packages/nodes-base/package.json +++ b/packages/nodes-base/package.json @@ -105,6 +105,7 @@ "dist/nodes/Asana/Asana.node.js", "dist/nodes/Asana/AsanaTrigger.node.js", "dist/nodes/Aws/AwsLambda.node.js", + "dist/nodes/Aws/AwsSes.node.js", "dist/nodes/Aws/AwsSns.node.js", "dist/nodes/Bitbucket/BitbucketTrigger.node.js", "dist/nodes/Bitly/Bitly.node.js",