Skip to content

Commit b58c3fd

Browse files
add replacemailvaribles function to change varibale from custom mail
1 parent 9d431af commit b58c3fd

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

apps/OpenSignServer/Utils.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,24 @@ export const color = [
1717
'#66ccff',
1818
'#ffffcc',
1919
];
20+
21+
export function replaceMailVaribles(subject, body, variables) {
22+
let replacedSubject = subject;
23+
let replacedBody = body;
24+
25+
for (const variable in variables) {
26+
const regex = new RegExp(`{{${variable}}}`, 'g');
27+
if (subject) {
28+
replacedSubject = replacedSubject.replace(regex, variables[variable]);
29+
}
30+
if (body) {
31+
replacedBody = replacedBody.replace(regex, variables[variable]);
32+
}
33+
}
34+
35+
const result = {
36+
subject: replacedSubject,
37+
body: replacedBody,
38+
};
39+
return result;
40+
}

0 commit comments

Comments
 (0)