forked from jensgertsen/sparkkiosk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mailersend.js
53 lines (48 loc) · 1.31 KB
/
mailersend.js
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
const Recipient = require("mailersend").Recipient;
const EmailParams = require("mailersend").EmailParams;
const MailerSend = require("mailersend");
const date = require('date-and-time');
var validator = require("email-validator");
module.exports = function (recipient, id, subject,mailtext, itemtext, itemprice, itemcurrency,key,template){
if(validator.validate(recipient) && key!="" && template!= ""){
const mailersend = new MailerSend({api_key: key,});
const recipients = [new Recipient(recipient, " ")];
const now = new Date();
const variables = [{
email: recipient,
substitutions: [
{
var: 'mailtext',
value: mailtext+""
},
{
var: 'datetime',
value: date.format(now, 'DD/MM/YYYY HH:mm')
},
{
'var': 'invoiceid',
'value': id+""
},
{
var: 'itemtext',
value: itemtext+""
},
{
var: 'itemprice',
value: itemprice+""
},
{
var: 'itemcurrency',
value: itemcurrency+""
}
],
}
];
const emailParams = new EmailParams()
.setRecipients(recipients)
.setSubject(subject)
.setTemplateId(template)
.setVariables(variables);
mailersend.send(emailParams);
}
}