This repository was archived by the owner on Jan 7, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprocesscube-google-docs-mail-template.html
More file actions
150 lines (116 loc) · 4.56 KB
/
processcube-google-docs-mail-template.html
File metadata and controls
150 lines (116 loc) · 4.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
<script type="text/javascript">
RED.nodes.registerType('processcube-google-docs-mail-template', {
category: 'ProcessCube Tools',
color: '#02AFD6',
defaults: {
name: { value: '' },
template_link: { value: '', type: 'str' },
template_link_type: { value: 'str'},
},
inputs: 1,
outputs: 1,
icon: 'font-awesome/fa-sign-in',
label: function () {
return this.name || 'processcube-google-docs-mail-template';
},
oneditprepare: function () {
$('#node-input-template_link').typedInput({
default: 'msg',
types: ['msg', 'str'],
});
$('#node-input-template_link').typedInput('value', this.template_link);
$('#node-input-template_link').typedInput('type', this.template_link_type);
},
oneditsave: function () {
(this.template_link = $('#node-input-template_link').typedInput('value')),
(this.template_link_type = $('#node-input-template_link').typedInput('type'));
},
});
</script>
<script type="text/html" data-template-name="processcube-google-docs-mail-template">
<div class="form-row">
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
<input type="text" id="node-input-name" placeholder="Name" />
</div>
<div class="form-row">
<label for="node-input-template_link"><i class="fa fa-tag"></i> Template Link</label>
<input type="text" id="node-input-template_link" placeholder="Template Link" />
</div>
</script>
<script type="text/markdown" data-help-name="processcube-google-docs-mail-template">
# Email Template Renderer (with Google Drive/Docs Support)
This Node-RED template module downloads a ZIP archive from a URL, extracts an HTML file and embedded images, replaces placeholders, and prepares the HTML content with inline attachments (CID) for email delivery.
## Google Drive / Docs Link Support
The ZIP file must be publicly accessible via a **shared Google Drive link** (at least “Anyone with the link can view”). The following link formats are supported:
```js
// Format 0: Google Docs (export as ZIP)
const editMatch = link.match(/https:\/\/docs\.google\.com\/document\/d\/([^/]+)/);
if (editMatch) {
const fileId = editMatch[1];
return `https://docs.google.com/document/d/${fileId}/export?format=zip`;
}
// Format 1: Google Drive – shared file
const fileMatch = link.match(/https:\/\/drive\.google\.com\/file\/d\/([^/]+)\/view/);
if (fileMatch) {
return `https://drive.google.com/uc?export=download&id=${fileMatch[1]}`;
}
// Format 2: Google Drive – open by ID
const openMatch = link.match(/https:\/\/drive\.google\.com\/open\?id=([^&]+)/);
if (openMatch) {
return `https://drive.google.com/uc?export=download&id=${openMatch[1]}`;
}
```
> Make sure that the file is shared with one of these formats and publicly accessible.
---
## Processing Steps
1. **Download** the ZIP archive from the URL.
2. **Extract** the contents (expects one HTML file in the root directory).
3. **Embed images**: All images referenced in `images/` will be replaced with `cid:` links.
4. **Replace placeholders** in the following formats:
- `{{field}}`
- `///field///`
5. **Output**:
- rendered HTML string
- `msg.attachments[]` containing Nodemailer-compatible inline files
---
## Inputs
### `template_link` (String||msg): The URL to the ZIP archive containing the HTML template and images.
### `payload` (JSON): Field to replace placeholders in the HTML template.
Fields for placeholder replacement. Example:
```json
{
"user_name": "Martin",
"newsletter_date": "May 5, 2025",
"announcement": "Our new album will be released soon!"
}
```
Used to replace `{{user_name}}` or `///user_name///` in the HTML template.
---
## Outputs
### `payload` (String)
The rendered HTML content with embedded CID references and replaced placeholders.
### `attachments` (Array)
Array of objects like:
```json
{
"filename": "image1.png",
"path": "/path/to/file/image1.png",
"cid": "image1"
}
```
---
## Example
```text
<p>Hello {{user_name}},</p>
<img src="images/image1.png">
```
Becomes:
```text
<p>Hello Martin,</p>
<img src="cid:image1">
```
---
## References
- [The ProcessCube Developer Network](https://processcube.io) – All documentation for the ProcessCube© platform
- [Node-RED Integration in ProcessCube©](https://processcube.io/docs/node-red) – Node-RED integration in ProcessCube©
</script>