mirror of
https://github.com/n8n-io/n8n.git
synced 2024-12-25 04:34:06 -08:00
⚡ 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:
parent
9b6f0ee3ee
commit
143c8bd326
|
@ -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',
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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';
|
||||
|
||||
|
|
|
@ -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',
|
||||
|
|
Loading…
Reference in a new issue