-
Notifications
You must be signed in to change notification settings - Fork 0
/
mail.js
48 lines (40 loc) · 1.3 KB
/
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
const mailConfig = require('./mailConfig.json');
function send(to, subject, message, html, attachments) {
// для отправки почты
let nodemailer = require('nodemailer');
//var transporter = nodemailer.createTransport({'service':'smtps','host': '192.168.0.254', 'port': '25', secure: false, ignoreTLS: true});
//var transporter = nodemailer.createTransport("SMTP",{
// service: "Yandex",
// host: 'smtp.yandex.ru',
// port: 465,
// secure: true, // true for 465, false for other ports
// auth: {
// user: "", // to be replaced by actual username and password
// pass: ""
// }
// });
let transporter = nodemailer.createTransport(mailConfig);
// verify connection configuration
transporter.verify(function(error, success) {
if (error) {
console.log(error);
} else {
console.log('Mail server is ready to take our messages');
}
});
let mailData = {
from: 'noreply@botboom.ru',
to: to,
subject: subject,
text: message
};
if(html !== undefined) mailData.html = html;
if(attachments) mailData.attachments = attachments;
transporter.sendMail(mailData, function(error, info){
if(error){
return console.log(error);
}
console.log('Message sent: ' + info.response);
});
}
module.exports.send = send;