From 3986356c8995998cb6ab392ae07f41efcb46d4bd Mon Sep 17 00:00:00 2001 From: Nicolas-nwb <64306440+Nicolas-nwb@users.noreply.github.com> Date: Thu, 25 Apr 2024 13:37:29 +0200 Subject: [PATCH] feat(Gmail Node): Add support for creating drafts using an alias (#8728) Co-authored-by: Jonathan Bennetts --- .../nodes/Google/Gmail/v2/DraftDescription.ts | 46 +++++++++++++++++++ .../nodes/Google/Gmail/v2/GmailV2.node.ts | 27 +++++++++++ 2 files changed, 73 insertions(+) diff --git a/packages/nodes-base/nodes/Google/Gmail/v2/DraftDescription.ts b/packages/nodes-base/nodes/Google/Gmail/v2/DraftDescription.ts index e6dd7d86a0..47b99c5762 100644 --- a/packages/nodes-base/nodes/Google/Gmail/v2/DraftDescription.ts +++ b/packages/nodes-base/nodes/Google/Gmail/v2/DraftDescription.ts @@ -186,6 +186,52 @@ export const draftFields: INodeProperties[] = [ default: {}, description: 'Array of supported attachments to add to the message', }, + { + displayName: 'BCC', + name: 'bccList', + type: 'string', + description: + 'The email addresses of the blind copy recipients. Multiple addresses can be separated by a comma. e.g. jay@getsby.com, jon@smith.com.', + placeholder: 'info@example.com', + default: '', + }, + { + displayName: 'CC', + name: 'ccList', + type: 'string', + description: + 'The email addresses of the copy recipients. Multiple addresses can be separated by a comma. e.g. jay@getsby.com, jon@smith.com.', + placeholder: 'info@example.com', + default: '', + }, + { + displayName: 'From Alias Name or ID', + name: 'fromAlias', + type: 'options', + default: '', + description: + 'Select the alias to send the email from. Choose from the list, or specify an ID using an expression.', + typeOptions: { + loadOptionsMethod: 'getGmailAliases', + }, + }, + { + displayName: 'Send Replies To', + name: 'replyTo', + type: 'string', + placeholder: 'reply@example.com', + default: '', + description: 'The email address that the reply message is sent to', + }, + { + displayName: 'To Email', + name: 'sendTo', + type: 'string', + default: '', + placeholder: 'info@example.com', + description: + 'The email addresses of the recipients. Multiple addresses can be separated by a comma. e.g. jay@getsby.com, jon@smith.com.', + }, ], }, { diff --git a/packages/nodes-base/nodes/Google/Gmail/v2/GmailV2.node.ts b/packages/nodes-base/nodes/Google/Gmail/v2/GmailV2.node.ts index ba8bdb668a..ab91df9135 100644 --- a/packages/nodes-base/nodes/Google/Gmail/v2/GmailV2.node.ts +++ b/packages/nodes-base/nodes/Google/Gmail/v2/GmailV2.node.ts @@ -197,6 +197,27 @@ export class GmailV2 implements INodeType { return returnData; }, + + async getGmailAliases(this: ILoadOptionsFunctions): Promise { + const returnData: INodePropertyOptions[] = []; + const { sendAs } = await googleApiRequest.call( + this, + 'GET', + '/gmail/v1/users/me/settings/sendAs', + ); + + for (const alias of sendAs || []) { + const displayName = alias.isDefault + ? `${alias.sendAsEmail} (Default)` + : alias.sendAsEmail; + returnData.push({ + name: displayName, + value: alias.sendAsEmail, + }); + } + + return returnData; + }, }, }; @@ -528,6 +549,7 @@ export class GmailV2 implements INodeType { let cc = ''; let bcc = ''; let replyTo = ''; + let fromAlias = ''; let threadId = null; if (options.sendTo) { @@ -546,6 +568,10 @@ export class GmailV2 implements INodeType { replyTo = prepareEmailsInput.call(this, options.replyTo as string, 'ReplyTo', i); } + if (options.fromAlias) { + fromAlias = options.fromAlias as string; + } + if (options.threadId && typeof options.threadId === 'string') { threadId = options.threadId; } @@ -567,6 +593,7 @@ export class GmailV2 implements INodeType { } const email: IEmail = { + from: fromAlias, to, cc, bcc,