saa_06 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- package/index.js +34 -0
- package/package.json +11 -0
package/index.js
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
const nodemailer = require("nodemailer");
|
2
|
+
const smtpTransport = require("nodemailer-smtp-transport");
|
3
|
+
|
4
|
+
function send(mailAddr, mailPass, message){
|
5
|
+
const transporter = nodemailer.createTransport(smtpTransport({
|
6
|
+
host: 'smtp.gmail.com',
|
7
|
+
port: 587,
|
8
|
+
secure: false,
|
9
|
+
auth: {
|
10
|
+
user: mailAddr,
|
11
|
+
pass: mailPass,
|
12
|
+
},
|
13
|
+
}));
|
14
|
+
|
15
|
+
const mailOptions = {
|
16
|
+
from: mailAddr,
|
17
|
+
to: mailAddr,
|
18
|
+
subject: 'lab_6',
|
19
|
+
text: message,
|
20
|
+
html: `<i>${message}</i>`,
|
21
|
+
};
|
22
|
+
|
23
|
+
transporter.sendMail(mailOptions, (error, info) => {
|
24
|
+
if (error) {
|
25
|
+
console.error(error);
|
26
|
+
throw new Error(error);
|
27
|
+
} else {
|
28
|
+
console.log('Email sent: ' + info.response);
|
29
|
+
return message;
|
30
|
+
}
|
31
|
+
});
|
32
|
+
}
|
33
|
+
|
34
|
+
exports.send = send;
|