feat(core): Add "Sent by n8n" attribution (#7183)

Github issue / Community forum post (link here to close automatically):

---------

Co-authored-by: Giulio Andreini <g.andreini@gmail.com>
This commit is contained in:
Michael Kret
2023-10-03 11:18:59 +03:00
committed by GitHub
parent f0a66873b9
commit 8f9fe6269b
20 changed files with 345 additions and 57 deletions

View File

@@ -435,19 +435,43 @@ export function prepareEmailsInput(
export function prepareEmailBody(
this: IExecuteFunctions | ILoadOptionsFunctions,
itemIndex: number,
appendAttribution = false,
instanceId?: string,
) {
const emailType = this.getNodeParameter('emailType', itemIndex) as string;
let message = (this.getNodeParameter('message', itemIndex, '') as string).trim();
let body = '';
let htmlBody = '';
if (emailType === 'html') {
htmlBody = (this.getNodeParameter('message', itemIndex, '') as string).trim();
} else {
body = (this.getNodeParameter('message', itemIndex, '') as string).trim();
if (appendAttribution) {
const attributionText = 'This email was sent automatically with ';
const link = `https://n8n.io/?utm_source=n8n-internal&utm_medium=powered_by&utm_campaign=${encodeURIComponent(
'n8n-nodes-base.gmail',
)}${instanceId ? '_' + instanceId : ''}`;
if (emailType === 'html') {
message = `
${message}
<br>
<br>
---
<br>
<em>${attributionText}<a href="${link}" target="_blank">n8n</a></em>
`;
} else {
message = `${message}\n\n---\n${attributionText}n8n\n${'https://n8n.io'}`;
}
}
return { body, htmlBody };
const body = {
body: '',
htmlBody: '',
};
if (emailType === 'html') {
body.htmlBody = message;
} else {
body.body = message;
}
return body;
}
export async function prepareEmailAttachments(