Welcome to the community @tino
Add there variables into the existing html template
You can replace the variables in the HTML using string.replace() in a function node.
Save the HTML file to signature.html. This file can be overwritten every time as it’s only used once while sending.
With a function node, you can also “create” the attachment. In other words, turn the HTML string to n8n binary data. Check n8n data structure..
The workflow should look something to the image below. You would have to replace the set node for the Typeform trigger and add a node to send emails depending on the email provider you are using.
The two important nodes here are: Replace Variables
and Create Binary Data
.
Function node Replace Variables
:
const data = $node["Set"].json
let html = $node["Function"].json.html
for (const key of Object.keys(data)) {
const regularExpression = new RegExp(`{${key}}`, 'g');
html = html.replace(regularExpression, data[key])
}
return [
{
json:{
html,
}
}
]
Function node Create Binary Data
:
const html = items[0].json.html;
return [
{
json: {},
binary: {
data: {
data: Buffer.from(html).toString('base64'),
mimeType: 'text/html; charset=UTF-8',
fileName: 'signature.html',
}
}
}
]
Example workflow
{
"nodes": [
{
"parameters": {},
"name": "Start",
"type": "n8n-nodes-base.start",
"typeVersion": 1,
"position": [
200,
390
]
},
{
"parameters": {
"functionCode": "return [\n {\n json: {\n html: `<h1>My name is: {name}, and I'm {age} years old</h1>`\n }\n }\n]"
},
"name": "Function",
"type": "n8n-nodes-base.function",
"typeVersion": 1,
"position": [
680,
300
],
"notesInFlow": true,
"notes": "Get HTML template"
},
{
"parameters": {
"values": {
"string": [
{
"name": "name",
"value": "ricardo"
},
{
"name": "age",
"value": "30"
}
],
"number": []
},
"options": {}
},
"name": "Set",
"type": "n8n-nodes-base.set",
"typeVersion": 1,
"position": [
450,
380
],
"notesInFlow": true,
"notes": "Mockup Typeform"
},
{
"parameters": {
"functionCode": "const data = $node[\"Set\"].json\nlet html = $node[\"Function\"].json.html\n\n\nfor (const key of Object.keys(data)) {\n const regularExpression = new RegExp(`{${key}}`, 'g');\n html = html.replace(regularExpression, data[key])\n}\n\nreturn [\n {\n json:{\n html,\n }\n }\n]\n\n"
},
"name": "Function1",
"type": "n8n-nodes-base.function",
"typeVersion": 1,
"position": [
1030,
290
],
"notesInFlow": true,
"notes": "Replace Variables"
},
{
"parameters": {
"functionCode": "const html = items[0].json.html;\n\nreturn [\n {\n json: {},\n binary: {\n data: {\n data: Buffer.from(html).toString('base64'),\n mimeType: 'text/html; charset=UTF-8',\n fileName: 'signature.html',\n }\n }\n }\n]\n\n\n\n"
},
"name": "Function2",
"type": "n8n-nodes-base.function",
"typeVersion": 1,
"position": [
1270,
290
],
"notesInFlow": true,
"notes": "Create Binary Data"
}
],
"connections": {
"Start": {
"main": [
[
{
"node": "Set",
"type": "main",
"index": 0
}
]
]
},
"Function": {
"main": [
[
{
"node": "Function1",
"type": "main",
"index": 0
}
]
]
},
"Set": {
"main": [
[
{
"node": "Function",
"type": "main",
"index": 0
}
]
]
},
"Function1": {
"main": [
[
{
"node": "Function2",
"type": "main",
"index": 0
}
]
]
}
}
}