-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmail.js
34 lines (30 loc) · 918 Bytes
/
mail.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
const mailer = require('nodemailer')
const pug = require('pug')
const server = 'localhost:3000'
const transport = mailer.createTransport({
host: 'smtp.mailtrap.io',
port: 2525,
auth: {
user: 'bde6ec1c45e0ce', // generated by Mailtrap
pass: '013978550e898b' // generated by Mailtrap
}
})
const mailOptions = {
from: '"Служба восстановления паролей" <srv@pwd_recover.com>',
to: '',
subject: 'Восстановление пароля',
text: '',
html: ''
}
exports.sendMail = (to, token, done) => {
const options = { link: `http://${server}/recover/${token}` }
mailOptions.to = to
mailOptions.html = pug.renderFile('./mail_templates/tmpl_main.pug', options)
transport.sendMail(mailOptions, (error, info) => {
if (error) {
console.log(error)
}
console.log('Message sent: %s, link: %s', info.messageId, options.link)
done(info)
})
}