-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
46 lines (41 loc) · 1.05 KB
/
index.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
'use strict';
const rp = require('request-promise')
// send an email
exports.sendMail = (params) => {
const payload = {
from: params.from,
personalizations: {
to: params.to,
dynamic_template_data: params.data
},
template_id: params.template_id
}
const options = {
method: 'POST',
uri: 'https://api.sendgrid.com/v3/mail/send',
body: payload,
headers: {
Authorization: 'Bearer ' + process.env.SENGRID_APIKEY,
'Content-Type': 'application/ json'
},
json: true // Automatically stringifies the body to JSON
}
return rp(options)
.then(function (response) {
return response
})
.catch(function (err) {
console.error(err)
return false
});
}
// send some email
exports.sendMails = paramsArray => {
let result = paramsArray.map(item => {
return sendMail(item)
})
return Promise.all(result)
.then(res => {
return res
})
}