diff --git a/packages/nodes-base/nodes/Google/Gmail/DraftDescription.ts b/packages/nodes-base/nodes/Google/Gmail/DraftDescription.ts index f0e0bbbd4..b2fd38cd3 100644 --- a/packages/nodes-base/nodes/Google/Gmail/DraftDescription.ts +++ b/packages/nodes-base/nodes/Google/Gmail/DraftDescription.ts @@ -81,6 +81,44 @@ export const draftFields = [ placeholder: 'Hello World!', description: 'The message subject.', }, + { + displayName: 'HTML', + name: 'includeHtml', + type: 'boolean', + displayOptions: { + show: { + resource: [ + 'draft', + ], + operation: [ + 'create', + ], + }, + }, + default: false, + description: 'Switch ON if the message should also be included as HTML.', + }, + { + displayName: 'HTML Message', + name: 'htmlMessage', + type: 'string', + default: '', + required: true, + displayOptions: { + show: { + includeHtml: [ + true, + ], + resource: [ + 'draft', + ], + operation: [ + 'create', + ], + }, + }, + description: 'The HTML message body.', + }, { displayName: 'Message', name: 'message', @@ -98,7 +136,7 @@ export const draftFields = [ }, }, placeholder: 'Hello World!', - description: 'The message body. This can be in HTML.', + description: 'The message body. If HTML formatted, then you have to add and activate the option "HTML content" in the "Additional Options" section.', }, { displayName: 'Additional Fields', diff --git a/packages/nodes-base/nodes/Google/Gmail/GenericFunctions.ts b/packages/nodes-base/nodes/Google/Gmail/GenericFunctions.ts index 923e22f21..c86752fcb 100644 --- a/packages/nodes-base/nodes/Google/Gmail/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Google/Gmail/GenericFunctions.ts @@ -133,20 +133,23 @@ export async function encodeEmail(email: IEmail) { const mailOptions = { to: email.to, - cc : email.cc, + cc: email.cc, bcc: email.bcc, replyTo: email.inReplyTo, references: email.reference, subject: email.subject, text: email.body, } as IDataObject; + if (email.htmlBody) { + mailOptions.html = email.htmlBody; + } if (email.attachments !== undefined && Array.isArray(email.attachments) && email.attachments.length > 0) { const attachments = email.attachments.map((attachment) => ({ filename: attachment.name, content: attachment.content, contentType: attachment.type, - encoding : 'base64', + encoding: 'base64', })); mailOptions.attachments = attachments; diff --git a/packages/nodes-base/nodes/Google/Gmail/Gmail.node.ts b/packages/nodes-base/nodes/Google/Gmail/Gmail.node.ts index ac42228b2..33c458db7 100644 --- a/packages/nodes-base/nodes/Google/Gmail/Gmail.node.ts +++ b/packages/nodes-base/nodes/Google/Gmail/Gmail.node.ts @@ -52,6 +52,7 @@ export interface IEmail { reference?: string; subject: string; body: string; + htmlBody?: string; attachments?: IDataObject[]; } @@ -325,6 +326,10 @@ export class Gmail implements INodeType { attachments: attachmentsList, }; + if (this.getNodeParameter('includeHtml', i, false) as boolean === true) { + email.htmlBody = this.getNodeParameter('htmlMessage', i) as string; + } + endpoint = '/gmail/v1/users/me/messages/send'; method = 'POST'; @@ -420,6 +425,10 @@ export class Gmail implements INodeType { attachments: attachmentsList, }; + if (this.getNodeParameter('includeHtml', i, false) as boolean === true) { + email.htmlBody = this.getNodeParameter('htmlMessage', i) as string; + } + endpoint = '/gmail/v1/users/me/messages/send'; method = 'POST'; @@ -620,6 +629,10 @@ export class Gmail implements INodeType { attachments: attachmentsList, }; + if (this.getNodeParameter('includeHtml', i, false) as boolean === true) { + email.htmlBody = this.getNodeParameter('htmlMessage', i) as string; + } + endpoint = '/gmail/v1/users/me/drafts'; method = 'POST'; diff --git a/packages/nodes-base/nodes/Google/Gmail/MessageDescription.ts b/packages/nodes-base/nodes/Google/Gmail/MessageDescription.ts index adc52bd66..581a13cb3 100644 --- a/packages/nodes-base/nodes/Google/Gmail/MessageDescription.ts +++ b/packages/nodes-base/nodes/Google/Gmail/MessageDescription.ts @@ -125,6 +125,46 @@ export const messageFields = [ placeholder: 'Hello World!', description: 'The message subject.', }, + { + displayName: 'HTML', + name: 'includeHtml', + type: 'boolean', + displayOptions: { + show: { + resource: [ + 'message', + ], + operation: [ + 'send', + 'reply', + ], + }, + }, + default: false, + description: 'Switch ON if the message should also be included as HTML.', + }, + { + displayName: 'HTML Message', + name: 'htmlMessage', + type: 'string', + default: '', + required: true, + displayOptions: { + show: { + includeHtml: [ + true, + ], + resource: [ + 'message', + ], + operation: [ + 'reply', + 'send', + ], + }, + }, + description: 'The HTML message body.', + }, { displayName: 'Message', name: 'message', @@ -142,8 +182,7 @@ export const messageFields = [ ], }, }, - placeholder: 'Hello World!', - description: 'The message body. This can be in HTML.', + description: 'Plain text message body.', }, { displayName: 'To Email',