@gov-cy/dsf-email-templates 1.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/mailtrap-test.yml +25 -0
- package/.github/workflows/tag-and-publish-on-version-change.yml +63 -0
- package/.github/workflows/unit-test.yml +22 -0
- package/CHANGELOG.md +76 -0
- package/LICENSE +21 -0
- package/NOTES.md +49 -0
- package/README.md +394 -0
- package/bin/dsf-email-templater.cmd +5 -0
- package/bin/dsf-email-templater.js +24 -0
- package/build/submission-email-small.html +124 -0
- package/build/submission-email.html +188 -0
- package/build/verification-email.html +85 -0
- package/package.json +41 -0
- package/src/DSFEmailRenderer.mjs +128 -0
- package/src/index.mjs +5 -0
- package/src/njk/components/body.njk +8 -0
- package/src/njk/components/bodyHeading.njk +27 -0
- package/src/njk/components/bodyList.njk +28 -0
- package/src/njk/components/bodyParagraph.njk +12 -0
- package/src/njk/components/footer.njk +20 -0
- package/src/njk/components/header.njk +35 -0
- package/src/njk/components/preHeader.njk +7 -0
- package/src/njk/components/success.njk +23 -0
- package/src/njk/govcyBase.njk +47 -0
- package/src/njk/govcyEmailElement.njk +44 -0
- package/src/njk/templates/submission-email-small.njk +47 -0
- package/src/njk/templates/submission-email.njk +65 -0
- package/src/njk/templates/verification-test.njk +33 -0
- package/test/mailtrap-njk.js +89 -0
- package/test/mailtrap.js +84 -0
- package/test/moca/unit.test.js +179 -0
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{# footer
|
|
2
|
+
@param {string} footerText The footerText. Will escape text
|
|
3
|
+
@returns govcy footer for emails html
|
|
4
|
+
#}
|
|
5
|
+
{% macro gocvyEmailFooter(params) -%}
|
|
6
|
+
<table border="0" cellpadding="0" cellspacing="0" width="100%" style="max-width: 600px;" >
|
|
7
|
+
<tr>
|
|
8
|
+
<td align="center" valign="top" style="padding:10px 16px 10px;border-top: 4px solid #ffad2d;background:#ebf1f3;background-color:#ebf1f3;">
|
|
9
|
+
<div style="font-family:Arial; font-size: 24px;text-align:left;margin-bottom: 10px;line-height:1;">
|
|
10
|
+
<a href="https://gov.cy" style="color:#000000; text-decoration: none;font-weight: 500;">
|
|
11
|
+
<strong style="color:#000000; text-decoration: none;font-weight: 500;">gov.cy</strong>
|
|
12
|
+
</a>
|
|
13
|
+
</div>
|
|
14
|
+
<div style="font-family:Arial;font-size:16px;text-align:left;margin-bottom: 10px;line-height:1;" >
|
|
15
|
+
{{ params.footerText}}
|
|
16
|
+
</div>
|
|
17
|
+
</td>
|
|
18
|
+
</tr>
|
|
19
|
+
</table>
|
|
20
|
+
{%- endmacro %}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{# header
|
|
2
|
+
@param {string} serviceName The service name. Will escape text
|
|
3
|
+
@param {string} name The name used in salutation. Will escape text
|
|
4
|
+
@param {string} lang The language used. Can be 'en','el'. Optional, default is 'el'.
|
|
5
|
+
@returns govcy header for emails html
|
|
6
|
+
#}
|
|
7
|
+
{% macro gocvyEmailHeader(params) -%}
|
|
8
|
+
{#- set default values -#}
|
|
9
|
+
{%- set lang = params.lang | default('el') -%}
|
|
10
|
+
{#- set language vars -#}
|
|
11
|
+
{%- set salutation -%}
|
|
12
|
+
{{- 'Dear' if lang=='en' -}}
|
|
13
|
+
{{- 'Αγαπητέ / Αγαπητή' if lang=='el' -}}
|
|
14
|
+
{%- endset -%}
|
|
15
|
+
<table border="0" cellpadding="0" cellspacing="0" width="100%" style="max-width: 600px;" >
|
|
16
|
+
<tr>
|
|
17
|
+
<!-- IMAGE -->
|
|
18
|
+
<td align="left" valign="top" style="padding: 12px 16px 0px;background:#31576f;background-color:#31576f;">
|
|
19
|
+
<img src="https://cdn.jsdelivr.net/gh/gov-cy/govdesign@main/govcylogo_v3.png" alt="gov.cy" border="0" />
|
|
20
|
+
</td>
|
|
21
|
+
</tr>
|
|
22
|
+
<tr>
|
|
23
|
+
<td align="left" valign="top" style="padding:0px 16px 12px;border-bottom: 4px solid #ffad2d;background:#31576f;background-color:#31576f;">
|
|
24
|
+
<!-- SERVICE NAME -->
|
|
25
|
+
<div style="font-family:Arial;font-size:18px;line-height:1.5;text-align:left; color:#ffffff;" >{{ params.serviceName }}</div>
|
|
26
|
+
</td>
|
|
27
|
+
</tr>
|
|
28
|
+
<tr>
|
|
29
|
+
<td align="center" valign="top" style="padding:20px 16px;">
|
|
30
|
+
<!-- SALUTATION -->
|
|
31
|
+
<div style="font-family:Arial;font-size:16px;line-height:1.5;text-align:left;" >{{ salutation }} {{params.name}}</div>
|
|
32
|
+
</td>
|
|
33
|
+
</tr>
|
|
34
|
+
</table>
|
|
35
|
+
{%- endmacro %}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{# pre header
|
|
2
|
+
@param {string} preText The pre header text. Will escape text
|
|
3
|
+
@returns govcy pre header for emails html
|
|
4
|
+
#}
|
|
5
|
+
{% macro gocvyEmailPreHeader(params) -%}
|
|
6
|
+
<div style="display:none;font-size:1px;color:#ffffff;line-height:1px;max-height:0px;max-width:0px;opacity:0;overflow:hidden;">{{params.preText}}</div>
|
|
7
|
+
{%- endmacro %}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{# pre success panel
|
|
2
|
+
@param {string} title The success title text. Will escape text
|
|
3
|
+
@param {string} body The success body text. Will escape text
|
|
4
|
+
@returns govcy success panel for emails html
|
|
5
|
+
#}
|
|
6
|
+
{% macro gocvyEmailSuccess(params) -%}
|
|
7
|
+
<table border="0" cellpadding="0" cellspacing="0" width="100%" style="padding:10px 0;max-width: 600px;background:#00703c;background-color:#00703c;" >
|
|
8
|
+
<tr>
|
|
9
|
+
<td align="center" valign="top" style="padding:10px 16px;">
|
|
10
|
+
<!-- Received -->
|
|
11
|
+
<div style="font-family:helvetica;font-size:24px;font-weight:bold;line-height:1.5;text-align:center;color:#ffffff;">{{ params.title }}</div>
|
|
12
|
+
</td>
|
|
13
|
+
</tr>
|
|
14
|
+
{%- if params.body -%}
|
|
15
|
+
<tr>
|
|
16
|
+
<td align="center" valign="top" style="padding:10px 16px;">
|
|
17
|
+
<!-- details -->
|
|
18
|
+
<div style="font-family:Arial;font-size:18px;line-height:1.5;text-align:center;color:#ffffff;">{{ params.body }}</div>
|
|
19
|
+
</td>
|
|
20
|
+
</tr>
|
|
21
|
+
{%- endif -%}
|
|
22
|
+
</table>
|
|
23
|
+
{%- endmacro %}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="{% block lang %}el{% endblock %}" xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office">
|
|
3
|
+
<head>
|
|
4
|
+
<title>{% block subject %}Untitled Page{% endblock %}</title>
|
|
5
|
+
<!--[if !mso]><!-->
|
|
6
|
+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
|
7
|
+
<!--<![endif]-->
|
|
8
|
+
<!--[if (gte mso 9)|(IE)]>
|
|
9
|
+
<style>
|
|
10
|
+
li {
|
|
11
|
+
margin-left:10px !important;
|
|
12
|
+
mso-special-format: bullet;
|
|
13
|
+
}
|
|
14
|
+
</style>
|
|
15
|
+
<![endif]-->
|
|
16
|
+
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
|
17
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
18
|
+
</head>
|
|
19
|
+
<body>
|
|
20
|
+
<!-- PRE HEADER TEXT -->
|
|
21
|
+
{% block pre %}{% endblock %}
|
|
22
|
+
<table border="0" cellpadding="0" cellspacing="0" width="100%">
|
|
23
|
+
<tr>
|
|
24
|
+
<td align="center">
|
|
25
|
+
<!--[if mso]>
|
|
26
|
+
<table align="center" border="0" cellspacing="0" cellpadding="0" width="600">
|
|
27
|
+
<tr>
|
|
28
|
+
<td align="center" valign="top" width="600">
|
|
29
|
+
<![endif]-->
|
|
30
|
+
<!-- HEADER -->
|
|
31
|
+
{% block header %}{% endblock %}
|
|
32
|
+
<!-- SUCCESS -->
|
|
33
|
+
{% block success %}{% endblock %}
|
|
34
|
+
<!-- BODY -->
|
|
35
|
+
{% block body %}{% endblock %}
|
|
36
|
+
<!-- FOOTER -->
|
|
37
|
+
{% block footer %}{% endblock %}
|
|
38
|
+
<!--[if mso]>
|
|
39
|
+
</td>
|
|
40
|
+
</tr>
|
|
41
|
+
</table>
|
|
42
|
+
<![endif]-->
|
|
43
|
+
</td>
|
|
44
|
+
</tr>
|
|
45
|
+
</table>
|
|
46
|
+
</body>
|
|
47
|
+
</html>
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{% macro govcyEmailElement(component, params) -%}
|
|
2
|
+
{#- preHeader -#}
|
|
3
|
+
{%- if component == 'preHeader' -%}
|
|
4
|
+
{%- from "./components/preHeader.njk" import gocvyEmailPreHeader -%}
|
|
5
|
+
{{ gocvyEmailPreHeader(params) }}
|
|
6
|
+
{#- header -#}
|
|
7
|
+
{%- elif component == 'header' -%}
|
|
8
|
+
{%- from "./components/header.njk" import gocvyEmailHeader -%}
|
|
9
|
+
{{ gocvyEmailHeader(params) }}
|
|
10
|
+
{#- success -#}
|
|
11
|
+
{%- elif component == 'success' -%}
|
|
12
|
+
{%- from "./components/success.njk" import gocvyEmailSuccess -%}
|
|
13
|
+
{{ gocvyEmailSuccess(params) }}
|
|
14
|
+
{#- bodyList -#}
|
|
15
|
+
{%- elif component == 'bodyList' -%}
|
|
16
|
+
{%- from "./components/bodyList.njk" import gocvyEmailBodyList -%}
|
|
17
|
+
{{ gocvyEmailBodyList(params) }}
|
|
18
|
+
{#- footer -#}
|
|
19
|
+
{%- elif component == 'footer' -%}
|
|
20
|
+
{%- from "./components/footer.njk" import gocvyEmailFooter -%}
|
|
21
|
+
{{ gocvyEmailFooter(params) }}
|
|
22
|
+
{#- body -#}
|
|
23
|
+
{%- elif component == 'body' -%}
|
|
24
|
+
{%- from "./components/body.njk" import gocvyEmailBody -%}
|
|
25
|
+
{%- call gocvyEmailBody(params) -%}
|
|
26
|
+
{{ caller() }}
|
|
27
|
+
{%- endcall -%}
|
|
28
|
+
{#- bodyHeading -#}
|
|
29
|
+
{%- elif component == 'bodyHeading' -%}
|
|
30
|
+
{%- from "./components/bodyHeading.njk" import gocvyEmailBodyHeading -%}
|
|
31
|
+
{%- call gocvyEmailBodyHeading(params) -%}
|
|
32
|
+
{{ caller() }}
|
|
33
|
+
{%- endcall -%}
|
|
34
|
+
{#- bodyParagraph -#}
|
|
35
|
+
{%- elif component == 'bodyParagraph' -%}
|
|
36
|
+
{%- from "./components/bodyParagraph.njk" import gocvyEmailBodyParagraph -%}
|
|
37
|
+
{%- call gocvyEmailBodyParagraph(params) -%}
|
|
38
|
+
{{ caller() }}
|
|
39
|
+
{%- endcall -%}
|
|
40
|
+
{%- else -%}
|
|
41
|
+
{# Handle unknown component types #}
|
|
42
|
+
Unknown component: {{ component }}
|
|
43
|
+
{%- endif -%}
|
|
44
|
+
{%- endmacro %}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
{# extend the base html #}
|
|
2
|
+
{% extends "govcyBase.njk" %}
|
|
3
|
+
{# import components #}
|
|
4
|
+
{% from "govcyEmailElement.njk" import govcyEmailElement %}
|
|
5
|
+
{# set language #}
|
|
6
|
+
{% set lang='en'%}
|
|
7
|
+
{# set the blocks of the base template #}
|
|
8
|
+
{# language block #}
|
|
9
|
+
{% block lang %}{{lang}}{% endblock %}
|
|
10
|
+
{# subject block #}
|
|
11
|
+
{% block subject %}Service email{% endblock %}
|
|
12
|
+
{# pre header block #}
|
|
13
|
+
{% block pre -%}{{ govcyEmailElement ('preHeader',{preText:'The pre header text'}) }}{%- endblock %}
|
|
14
|
+
{# header block #}
|
|
15
|
+
{% block header -%}
|
|
16
|
+
{# use the header component #}
|
|
17
|
+
{{ govcyEmailElement ('header',{serviceName:'Service name', name:'First and Last name',lang:lang}) }}
|
|
18
|
+
{%- endblock %}
|
|
19
|
+
{# success block #}
|
|
20
|
+
{% block success -%}
|
|
21
|
+
{# use the email success component #}
|
|
22
|
+
{{ govcyEmailElement ('success',
|
|
23
|
+
{
|
|
24
|
+
title:'Success messasage',
|
|
25
|
+
body:'Lorem ipsum'
|
|
26
|
+
}
|
|
27
|
+
) }}
|
|
28
|
+
{%- endblock %}
|
|
29
|
+
{# body block #}
|
|
30
|
+
{% block body -%}
|
|
31
|
+
{# use the body component #}
|
|
32
|
+
{% call govcyEmailElement('body') -%}
|
|
33
|
+
{# use combinatopn of body components to complete the body #}
|
|
34
|
+
{% call govcyEmailElement('bodyHeading',{headinLevel:1}) -%}
|
|
35
|
+
Heading 1
|
|
36
|
+
{%- endcall %}
|
|
37
|
+
{% call govcyEmailElement('bodyParagraph') -%}
|
|
38
|
+
Body
|
|
39
|
+
{%- endcall %}
|
|
40
|
+
{{ govcyEmailElement ('bodyList',{type:'ol', items: ["item 1", "item 2", "item 3"]}) }}
|
|
41
|
+
{%- endcall%}
|
|
42
|
+
{%- endblock %}
|
|
43
|
+
{# footer block #}
|
|
44
|
+
{% block footer -%}
|
|
45
|
+
{# use the footer component #}
|
|
46
|
+
{{ govcyEmailElement ('footer',{footerText:'Service name'}) }}
|
|
47
|
+
{%- endblock %}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
{# extend the base html #}
|
|
2
|
+
{% extends "govcyBase.njk" %}
|
|
3
|
+
{# import components #}
|
|
4
|
+
{% from "govcyEmailElement.njk" import govcyEmailElement %}
|
|
5
|
+
{# set language #}
|
|
6
|
+
{% set lang='el'%}
|
|
7
|
+
{# set the blocks of the base template #}
|
|
8
|
+
{# language block #}
|
|
9
|
+
{% block lang %}{{lang}}{% endblock %}
|
|
10
|
+
{# subject block #}
|
|
11
|
+
{% block subject %}Service email{% endblock %}
|
|
12
|
+
{# pre header block #}
|
|
13
|
+
{% block pre -%}{{ govcyEmailElement ('preHeader',{preText:'The pre header text'}) }}{%- endblock %}
|
|
14
|
+
{# header block #}
|
|
15
|
+
{% block header -%}
|
|
16
|
+
{# use the header component #}
|
|
17
|
+
{{ govcyEmailElement ('header',{serviceName:'Service name', name:'First and Last name',lang:lang}) }}
|
|
18
|
+
{%- endblock %}
|
|
19
|
+
{# success block #}
|
|
20
|
+
{% block success -%}
|
|
21
|
+
{# use the email success component #}
|
|
22
|
+
{{ govcyEmailElement ('success',
|
|
23
|
+
{
|
|
24
|
+
title:'Έχουμε λάβει την αίτησή σας',
|
|
25
|
+
body:'Η ημερομηνία της αίτησης είναι 12/1/2024 και ο αριθμός αναφοράς σας είναι DSF123456789.'}
|
|
26
|
+
) }}
|
|
27
|
+
{%- endblock %}
|
|
28
|
+
{# body block #}
|
|
29
|
+
{% block body -%}
|
|
30
|
+
{# use the body component #}
|
|
31
|
+
{% call govcyEmailElement('body') -%}
|
|
32
|
+
{# use combinatopn of body components to complete the body #}
|
|
33
|
+
{% call govcyEmailElement('bodyHeading',{headinLevel:1}) -%}
|
|
34
|
+
Heading 1
|
|
35
|
+
{%- endcall %}
|
|
36
|
+
{% call govcyEmailElement('bodyParagraph') -%}
|
|
37
|
+
Αν χρειαστούμε οποιοδήποτε άλλο στοιχείο κατά τη διάρκεια εξέτασης της αίτησής σας, θα επικοινωνήσουμε μαζί σας
|
|
38
|
+
{%- endcall %}
|
|
39
|
+
{% call govcyEmailElement('bodyHeading',{headinLevel:2}) -%}
|
|
40
|
+
Heading 2
|
|
41
|
+
{%- endcall %}
|
|
42
|
+
{% call govcyEmailElement('bodyParagraph') -%}
|
|
43
|
+
Lorem ipsum kai xero go kouventes
|
|
44
|
+
{%- endcall %}
|
|
45
|
+
{% call govcyEmailElement('bodyHeading',{headinLevel:3}) -%}
|
|
46
|
+
Heading 3
|
|
47
|
+
{%- endcall %}
|
|
48
|
+
{% call govcyEmailElement('bodyParagraph') -%}
|
|
49
|
+
Lorem ipsum kai xero go kouventes
|
|
50
|
+
{%- endcall %}
|
|
51
|
+
{% call govcyEmailElement('bodyHeading',{headinLevel:4}) -%}
|
|
52
|
+
Heading 4
|
|
53
|
+
{%- endcall %}
|
|
54
|
+
{% call govcyEmailElement('bodyParagraph') -%}
|
|
55
|
+
Lorem ipsum kai xero go kouventes
|
|
56
|
+
{%- endcall %}
|
|
57
|
+
{{ govcyEmailElement ('bodyList',{type:'ol', items: ["xero -", "go", "kouvente"]}) }}
|
|
58
|
+
{{ govcyEmailElement ('bodyList',{type:'ul', items: ['<a href="#">xero</a>', "go", "kouvente"]}) }}
|
|
59
|
+
{%- endcall%}
|
|
60
|
+
{%- endblock %}
|
|
61
|
+
{# footer block #}
|
|
62
|
+
{% block footer -%}
|
|
63
|
+
{# use the footer component #}
|
|
64
|
+
{{ govcyEmailElement ('footer',{footerText:'Όνομα υπηρεσίας'}) }}
|
|
65
|
+
{%- endblock %}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{# extend the base html #}
|
|
2
|
+
{% extends "govcyBase.njk" %}
|
|
3
|
+
{# import components #}
|
|
4
|
+
{% from "govcyEmailElement.njk" import govcyEmailElement %}
|
|
5
|
+
{# set language #}
|
|
6
|
+
{% set lang='el'%}
|
|
7
|
+
{# set the blocks of the base template #}
|
|
8
|
+
{# language block #}
|
|
9
|
+
{% block lang %}{{lang}}{% endblock %}
|
|
10
|
+
{# subject block #}
|
|
11
|
+
{% block subject %}Service email{% endblock %}
|
|
12
|
+
{# pre header block #}
|
|
13
|
+
{% block pre -%}{{ govcyEmailElement ('preHeader',{preText:'The pre header text'}) }}{%- endblock %}
|
|
14
|
+
{# header block #}
|
|
15
|
+
{% block header -%}
|
|
16
|
+
{# use the header component #}
|
|
17
|
+
{{ govcyEmailElement ('header',{serviceName:'Service name', name:'First and Last name',lang:lang}) }}
|
|
18
|
+
{%- endblock %}
|
|
19
|
+
{# body block #}
|
|
20
|
+
{% block body -%}
|
|
21
|
+
{# use the body component #}
|
|
22
|
+
{% call govcyEmailElement('body') -%}
|
|
23
|
+
{# use combinatopn of body components to complete the body #}
|
|
24
|
+
{% call govcyEmailElement('bodyHeading',{headinLevel:1}) -%}
|
|
25
|
+
Verify code: 12234
|
|
26
|
+
{%- endcall %}
|
|
27
|
+
{%- endcall%}
|
|
28
|
+
{%- endblock %}
|
|
29
|
+
{# footer block #}
|
|
30
|
+
{% block footer -%}
|
|
31
|
+
{# use the footer component #}
|
|
32
|
+
{{ govcyEmailElement ('footer',{footerText:'Όνομα υπηρεσίας'}) }}
|
|
33
|
+
{%- endblock %}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Send test email on you mailtrap account.
|
|
4
|
+
*
|
|
5
|
+
* To run the script takes 1 argument which is the path of t file for the body of the email
|
|
6
|
+
*
|
|
7
|
+
* for example:
|
|
8
|
+
*
|
|
9
|
+
* ```
|
|
10
|
+
* node .\test\mailtrap.js build/test.html
|
|
11
|
+
* ```
|
|
12
|
+
*
|
|
13
|
+
* Note that to use you need to set the mailtrap username and password as followes:
|
|
14
|
+
*
|
|
15
|
+
* ```
|
|
16
|
+
* #on powershell
|
|
17
|
+
* $env:MAILTRAP_USERNAME = 'xxxxxxxxx'
|
|
18
|
+
* $env:MAILTRAP_PASSWORD = 'yyyyyyyy'
|
|
19
|
+
|
|
20
|
+
* #on windows
|
|
21
|
+
* set MAILTRAP_USERNAME=xxxxxxxxx
|
|
22
|
+
* set MAILTRAP_PASSWORD=yyyyyyyy
|
|
23
|
+
|
|
24
|
+
* # On Unix
|
|
25
|
+
* export MAILTRAP_USERNAME=xxxxxxxxx
|
|
26
|
+
* export MAILTRAP_PASSWORD=yyyyyyyy
|
|
27
|
+
|
|
28
|
+
* #in javascript
|
|
29
|
+
* cap['browserstack.username'] = process.env.MAILTRAP_USERNAME || 'xxxxxxxxx';
|
|
30
|
+
* cap['browserstack.accessKey'] = process.env.MAILTRAP_PASSWORD || 'yyyyyyyy';
|
|
31
|
+
* ```
|
|
32
|
+
*
|
|
33
|
+
*/
|
|
34
|
+
import nodemailer from 'nodemailer';
|
|
35
|
+
import fs from 'fs';
|
|
36
|
+
import { DSFEmailRenderer } from '../src/index.mjs';
|
|
37
|
+
import { exit } from 'process';
|
|
38
|
+
|
|
39
|
+
// async..await is not allowed in global scope, must use a wrapper
|
|
40
|
+
async function testMailtrap() {
|
|
41
|
+
|
|
42
|
+
const myArgs = process.argv.slice(2);
|
|
43
|
+
|
|
44
|
+
if (myArgs.length < 1) {
|
|
45
|
+
console.log('ERROR: Argument not specified. Specify the path of the HTML file for the body of the email.');
|
|
46
|
+
process.exit(1);
|
|
47
|
+
}
|
|
48
|
+
const renderer = new DSFEmailRenderer();
|
|
49
|
+
//render html
|
|
50
|
+
const htmlBody = await renderer.renderFromFile(myArgs[0]);
|
|
51
|
+
|
|
52
|
+
// Generate test SMTP service account from ethereal.email
|
|
53
|
+
// Only needed if you don't have a real mail account for testing
|
|
54
|
+
let testAccount = await nodemailer.createTestAccount();
|
|
55
|
+
|
|
56
|
+
// create reusable transporter object using the default SMTP transport
|
|
57
|
+
let transporter = nodemailer.createTransport({
|
|
58
|
+
host: "smtp.mailtrap.io",
|
|
59
|
+
port: 2525,
|
|
60
|
+
auth: {
|
|
61
|
+
user: process.env.MAILTRAP_USERNAME,
|
|
62
|
+
pass: process.env.MAILTRAP_PASSWORD
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
// send mail with defined transport object
|
|
67
|
+
let info = await transporter.sendMail({
|
|
68
|
+
from: 'govcy" <noreply@gov.cy>', // sender address
|
|
69
|
+
to: "test@dits.dmrid.gov.cy", // list of receivers
|
|
70
|
+
subject: "{{SERVICE-NAME}}", // Subject line
|
|
71
|
+
// text: `Text`, // plain text body
|
|
72
|
+
html: htmlBody
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
console.log("Message sent: %s", info.messageId);
|
|
76
|
+
|
|
77
|
+
// Preview only available when sending through an Ethereal account
|
|
78
|
+
console.log("Preview URL: %s", nodemailer.getTestMessageUrl(info));
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// Call testMailtrap() and handle errors
|
|
82
|
+
testMailtrap()
|
|
83
|
+
.then(() => {
|
|
84
|
+
console.log('Mailtrap test successful');
|
|
85
|
+
})
|
|
86
|
+
.catch((error) => {
|
|
87
|
+
console.error('An error occurred:', error);
|
|
88
|
+
process.exit(1); // Exit with a non-zero status code
|
|
89
|
+
});
|
package/test/mailtrap.js
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Send test email on you mailtrap account.
|
|
4
|
+
*
|
|
5
|
+
* To run the script takes 1 argument which is the path of njk file to render the body of the email
|
|
6
|
+
*
|
|
7
|
+
* for example:
|
|
8
|
+
*
|
|
9
|
+
* ```
|
|
10
|
+
* node .\test\mailtrap.js build/test.html
|
|
11
|
+
* ```
|
|
12
|
+
*
|
|
13
|
+
* Note that to use you need to set the mailtrap username and password as followes:
|
|
14
|
+
*
|
|
15
|
+
* ```
|
|
16
|
+
* #on powershell
|
|
17
|
+
* $env:MAILTRAP_USERNAME = 'xxxxxxxxx'
|
|
18
|
+
* $env:MAILTRAP_PASSWORD = 'yyyyyyyy'
|
|
19
|
+
|
|
20
|
+
* #on windows
|
|
21
|
+
* set MAILTRAP_USERNAME=xxxxxxxxx
|
|
22
|
+
* set MAILTRAP_PASSWORD=yyyyyyyy
|
|
23
|
+
|
|
24
|
+
* # On Unix
|
|
25
|
+
* export MAILTRAP_USERNAME=xxxxxxxxx
|
|
26
|
+
* export MAILTRAP_PASSWORD=yyyyyyyy
|
|
27
|
+
|
|
28
|
+
* #in javascript
|
|
29
|
+
* cap['browserstack.username'] = process.env.MAILTRAP_USERNAME || 'xxxxxxxxx';
|
|
30
|
+
* cap['browserstack.accessKey'] = process.env.MAILTRAP_PASSWORD || 'yyyyyyyy';
|
|
31
|
+
* ```
|
|
32
|
+
*
|
|
33
|
+
*/
|
|
34
|
+
import nodemailer from 'nodemailer';
|
|
35
|
+
import fs from 'fs';
|
|
36
|
+
import { exit } from 'process';
|
|
37
|
+
|
|
38
|
+
// async..await is not allowed in global scope, must use a wrapper
|
|
39
|
+
async function testMailtrap() {
|
|
40
|
+
|
|
41
|
+
const myArgs = process.argv.slice(2);
|
|
42
|
+
|
|
43
|
+
if (myArgs.length < 1) {
|
|
44
|
+
console.log('ERROR: Argument not specified. Specify the path of the HTML file for the body of the email.');
|
|
45
|
+
process.exit(1);
|
|
46
|
+
}
|
|
47
|
+
// Generate test SMTP service account from ethereal.email
|
|
48
|
+
// Only needed if you don't have a real mail account for testing
|
|
49
|
+
let testAccount = await nodemailer.createTestAccount();
|
|
50
|
+
|
|
51
|
+
// create reusable transporter object using the default SMTP transport
|
|
52
|
+
let transporter = nodemailer.createTransport({
|
|
53
|
+
host: "smtp.mailtrap.io",
|
|
54
|
+
port: 2525,
|
|
55
|
+
auth: {
|
|
56
|
+
user: process.env.MAILTRAP_USERNAME,
|
|
57
|
+
pass: process.env.MAILTRAP_PASSWORD
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
// send mail with defined transport object
|
|
62
|
+
let info = await transporter.sendMail({
|
|
63
|
+
from: 'govcy" <noreply@gov.cy>', // sender address
|
|
64
|
+
to: "test@dits.dmrid.gov.cy", // list of receivers
|
|
65
|
+
subject: "{{SERVICE-NAME}}", // Subject line
|
|
66
|
+
// text: `Text`, // plain text body
|
|
67
|
+
html: fs.readFileSync(myArgs[0])
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
console.log("Message sent: %s", info.messageId);
|
|
71
|
+
|
|
72
|
+
// Preview only available when sending through an Ethereal account
|
|
73
|
+
console.log("Preview URL: %s", nodemailer.getTestMessageUrl(info));
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// Call testMailtrap() and handle errors
|
|
77
|
+
testMailtrap()
|
|
78
|
+
.then(() => {
|
|
79
|
+
console.log('Mailtrap test successful');
|
|
80
|
+
})
|
|
81
|
+
.catch((error) => {
|
|
82
|
+
console.error('An error occurred:', error);
|
|
83
|
+
process.exit(1); // Exit with a non-zero status code
|
|
84
|
+
});
|