Allow Gmail node to send messages formatted as HTML (#1285)

* Allowing Gmail node to send messages formatted as HTML

* Improving message field description

* Fixing lint issues

* Adding missing trailing comma

*  Small improvements to GMail-Node

Co-authored-by: Jan Oberhauser <jan.oberhauser@gmail.com>
This commit is contained in:
Omar Ajoue 2021-01-07 11:58:28 +01:00 committed by GitHub
parent 9b6f0ee3ee
commit 143c8bd326
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 98 additions and 5 deletions

View file

@ -81,6 +81,44 @@ export const draftFields = [
placeholder: 'Hello World!', placeholder: 'Hello World!',
description: 'The message subject.', 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', displayName: 'Message',
name: 'message', name: 'message',
@ -98,7 +136,7 @@ export const draftFields = [
}, },
}, },
placeholder: 'Hello World!', 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', displayName: 'Additional Fields',

View file

@ -133,20 +133,23 @@ export async function encodeEmail(email: IEmail) {
const mailOptions = { const mailOptions = {
to: email.to, to: email.to,
cc : email.cc, cc: email.cc,
bcc: email.bcc, bcc: email.bcc,
replyTo: email.inReplyTo, replyTo: email.inReplyTo,
references: email.reference, references: email.reference,
subject: email.subject, subject: email.subject,
text: email.body, text: email.body,
} as IDataObject; } as IDataObject;
if (email.htmlBody) {
mailOptions.html = email.htmlBody;
}
if (email.attachments !== undefined && Array.isArray(email.attachments) && email.attachments.length > 0) { if (email.attachments !== undefined && Array.isArray(email.attachments) && email.attachments.length > 0) {
const attachments = email.attachments.map((attachment) => ({ const attachments = email.attachments.map((attachment) => ({
filename: attachment.name, filename: attachment.name,
content: attachment.content, content: attachment.content,
contentType: attachment.type, contentType: attachment.type,
encoding : 'base64', encoding: 'base64',
})); }));
mailOptions.attachments = attachments; mailOptions.attachments = attachments;

View file

@ -52,6 +52,7 @@ export interface IEmail {
reference?: string; reference?: string;
subject: string; subject: string;
body: string; body: string;
htmlBody?: string;
attachments?: IDataObject[]; attachments?: IDataObject[];
} }
@ -325,6 +326,10 @@ export class Gmail implements INodeType {
attachments: attachmentsList, 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'; endpoint = '/gmail/v1/users/me/messages/send';
method = 'POST'; method = 'POST';
@ -420,6 +425,10 @@ export class Gmail implements INodeType {
attachments: attachmentsList, 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'; endpoint = '/gmail/v1/users/me/messages/send';
method = 'POST'; method = 'POST';
@ -620,6 +629,10 @@ export class Gmail implements INodeType {
attachments: attachmentsList, 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'; endpoint = '/gmail/v1/users/me/drafts';
method = 'POST'; method = 'POST';

View file

@ -125,6 +125,46 @@ export const messageFields = [
placeholder: 'Hello World!', placeholder: 'Hello World!',
description: 'The message subject.', 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', displayName: 'Message',
name: 'message', name: 'message',
@ -142,8 +182,7 @@ export const messageFields = [
], ],
}, },
}, },
placeholder: 'Hello World!', description: 'Plain text message body.',
description: 'The message body. This can be in HTML.',
}, },
{ {
displayName: 'To Email', displayName: 'To Email',