-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
41 lines (33 loc) · 1.02 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
const nodemailer = require('nodemailer')
const { readFileSync } = require('fs')
const { mountHelperOptions } = require('./helpers')
let config
try {
config = require('./send-it.config')
} catch (error) {
throw new Error('`send-it.config.js` not found on this level directory', error)
}
const transporter = nodemailer.createTransport({
service: 'gmail',
secure: false,
port: 25,
auth: {
user: config.email,
pass: config.password
},
tls: {
rejectUnauthorized: false
}
})
const template = readFileSync('./templates/default.html', 'utf8')
console.log('* Using', config.email)
const senders = config.recipients.map(async recipe => {
const HELPER_OPTIONS = await mountHelperOptions({ ...config, template, recipe })
return new Promise((resolve, reject) =>
transporter.sendMail(HELPER_OPTIONS, (error, info) => error ? reject(error) : resolve(info))
)
})
Promise
.all(senders)
.then(() => console.log('* All email has been sent..'))
.catch(error => console.log('* Some error happen :(', error))