Skip to content

feat(Gmail Node): Add support for creating drafts using an alias #8728

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions packages/nodes-base/nodes/Google/Gmail/v2/DraftDescription.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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. [email protected], [email protected].',
placeholder: '[email protected]',
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. [email protected], [email protected].',
placeholder: '[email protected]',
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 <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>.',
typeOptions: {
loadOptionsMethod: 'getGmailAliases',
},
},
{
displayName: 'Send Replies To',
name: 'replyTo',
type: 'string',
placeholder: '[email protected]',
default: '',
description: 'The email address that the reply message is sent to',
},
{
displayName: 'To Email',
name: 'sendTo',
type: 'string',
default: '',
placeholder: '[email protected]',
description:
'The email addresses of the recipients. Multiple addresses can be separated by a comma. e.g. [email protected], [email protected].',
},
],
},
{
Expand Down
27 changes: 27 additions & 0 deletions packages/nodes-base/nodes/Google/Gmail/v2/GmailV2.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,27 @@ export class GmailV2 implements INodeType {

return returnData;
},

async getGmailAliases(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
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;
},
},
};

Expand Down Expand Up @@ -528,6 +549,7 @@ export class GmailV2 implements INodeType {
let cc = '';
let bcc = '';
let replyTo = '';
let fromAlias = '';
let threadId = null;

if (options.sendTo) {
Expand All @@ -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;
}
Expand All @@ -567,6 +593,7 @@ export class GmailV2 implements INodeType {
}

const email: IEmail = {
from: fromAlias,
to,
cc,
bcc,
Expand Down