Adding an HTML Message to msg.html
There are scenarios when sending email out of a flow where it would be advantageous to include additional content into the HTML of an existing email. For example, imagine a case where a user reports a potential phishing email which turns out to not be a phishing attempt. In this scenario, the flow should be able to send back the reported email with a prefix indicating the message appears to be safe.
The following function node, which can be imported into your flow by copying the text and importing from the clipboard, adds a prefix to an email message with informational text. To use the node, the flow message must already have the msg.html
property.
[
{
"id": "cd67692d.acc258",
"type": "function",
"z": "2c0c3b83.4ee754",
"name": "Insert HTML prefix into msg.html",
"func": "let information = '<b>This is my message prefix</b>' +\n '<p>More data here</p>';\n\n\n// Inserts the information string into the msg.html\n// field. Will perform the insert on the first\n// matching rule.\n// 1. Insert after the opening body tag.\n// 2. Insert after the closing head tag.\n// 3. Insert after the opening html tag.\n// 4. Insert at the begining of the msg.html string.\n// If there is no msg.html property, nothing is done.\nlet html = msg.html;\n\n// Find the body and insert the message.\nif ( html )\n{\n // Try inserting after the opening body tag.\n let pattern = /(<body[^>]*>)/img;\n let matches = pattern.exec(html);\n if ( matches && pattern.lastIndex > 0 )\n {\n msg.html = html.slice( 0, pattern.lastIndex ) + information + html.slice( pattern.lastIndex );\n return msg;\n }\n // Try inserting after the closing head tag.\n pattern = /(<\\/head>)/img;\n matches = pattern.exec(html);\n if ( matches && pattern.lastIndex > 0 )\n {\n msg.html = html.slice( 0, pattern.lastIndex ) + information + html.slice( pattern.lastIndex );\n return msg;\n }\n // Try inserting after the opening html tag.\n pattern = /(<html[^>]*>)/img;\n matches = pattern.exec(html);\n if ( matches && pattern.lastIndex > 0 )\n {\n msg.html = html.slice( 0, pattern.lastIndex ) + information + html.slice( pattern.lastIndex );\n return msg;\n }\n // Last resort, just prefix into the message.\n msg.html = information + html;\n}\nreturn msg;\n",
"outputs": 1,
"noerr": 0,
"x": 580,
"y": 380,
"wires": []
}
]
Metro Office Park
2950 Metro Drive, Suite 104
Bloomington, MN 55425
Phone: +1 952-500-8921
©Nevelex Labs, LLC. 2018-2024, All Rights Reserved.
EULA