sadlab05 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- package/05_02.js +59 -0
- package/05_03.js +8 -0
- package/05_04.js +9 -0
- package/m06_SAD.js +34 -0
- package/package.json +19 -0
package/05_02.js
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
const http = require('http');
|
2
|
+
const url = require('url');
|
3
|
+
const fs = require('fs');
|
4
|
+
const { parse } = require('querystring');
|
5
|
+
const nodemailer = require('nodemailer');
|
6
|
+
|
7
|
+
|
8
|
+
|
9
|
+
http.createServer((request, response) => {
|
10
|
+
response.writeHead(200, { 'Content-Type': 'text/html; charset=utf-8' });
|
11
|
+
|
12
|
+
if (url.parse(request.url).pathname === '/' && request.method === 'GET')
|
13
|
+
{
|
14
|
+
response.end(fs.readFileSync('./05_02.html'));
|
15
|
+
}
|
16
|
+
else if (url.parse(request.url).pathname === '/' && request.method === 'POST')
|
17
|
+
{
|
18
|
+
let body = '';
|
19
|
+
request.on('data', chunk => { body += chunk.toString(); });
|
20
|
+
|
21
|
+
request.on('end', () => {
|
22
|
+
let parm = parse(body);
|
23
|
+
const transporter = nodemailer.createTransport({
|
24
|
+
host: 'smtp.gmail.com',
|
25
|
+
port: 465,
|
26
|
+
secure: false,
|
27
|
+
service: 'Gmail',
|
28
|
+
auth: {
|
29
|
+
user: parm.sender,
|
30
|
+
pass: parm.password
|
31
|
+
}
|
32
|
+
});
|
33
|
+
|
34
|
+
const mailOptions = {
|
35
|
+
from: parm.sender,
|
36
|
+
to: parm.receiver,
|
37
|
+
subject: parm.subject,
|
38
|
+
text: parm.message
|
39
|
+
}
|
40
|
+
|
41
|
+
transporter.sendMail(mailOptions, (err, info) => {
|
42
|
+
err ? console.log(err) : console.log('Sent: ' + info.response);
|
43
|
+
})
|
44
|
+
|
45
|
+
response.end(`<h2>Отправитель: ${parm.sender}</br>Получатель: ${parm.receiver}
|
46
|
+
</br>Тема: ${parm.subject}</br>Сообщение: ${parm.message}</h2>`);
|
47
|
+
})
|
48
|
+
}
|
49
|
+
|
50
|
+
else
|
51
|
+
response.end('<html><body><h1>Error! Visit localhost:5000/</h1></body></html>');
|
52
|
+
}).listen(5000, () => console.log('Server running on http://localhost:5000/\n'));
|
53
|
+
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
|
package/05_03.js
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
const http = require('http');
|
2
|
+
const send = require('./m06_SAD.js');
|
3
|
+
|
4
|
+
http.createServer((request, response) => {
|
5
|
+
response.writeHead(200, { 'Content-Type': 'text/html; charset=utf-8' });
|
6
|
+
send('Hello World!');
|
7
|
+
response.end('<h2>Message sucessfully sent.</h2>');
|
8
|
+
}).listen(5000, () => console.log('Server running on http://localhost:5000/\n'));
|
package/05_04.js
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
|
2
|
+
const send = require("C:\\Users\\kseni\\AppData\\Roaming\\npm\\node_modules\\qwerty5");
|
3
|
+
const http = require('http');
|
4
|
+
|
5
|
+
http.createServer((req, res) => {
|
6
|
+
res.writeHead(200, { 'Content-Type': 'text/html; charset=utf-8' });
|
7
|
+
send('Hello world! Global module');
|
8
|
+
res.end('<h2>Message sucessfully sent.</h2>');
|
9
|
+
}).listen(5000, () => console.log('Server running on http://localhost:5000/\n'));
|
package/m06_SAD.js
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
const nodemailer = require('nodemailer');
|
2
|
+
|
3
|
+
const sender = 'typebooleanfalse@gmail.com';
|
4
|
+
const receiver = 'typebooleanfalse@gmail.com';
|
5
|
+
const password = 'kzik ujhr qtkw xfzw';
|
6
|
+
|
7
|
+
|
8
|
+
const transporter = nodemailer.createTransport({
|
9
|
+
host: 'smtp.gmail.com',
|
10
|
+
port: 465,
|
11
|
+
secure: false,
|
12
|
+
service: 'Gmail',
|
13
|
+
auth: {
|
14
|
+
user: sender,
|
15
|
+
pass: password
|
16
|
+
}
|
17
|
+
});
|
18
|
+
|
19
|
+
|
20
|
+
send = (message) =>
|
21
|
+
{
|
22
|
+
const mailOptions = {
|
23
|
+
from: sender,
|
24
|
+
to: receiver,
|
25
|
+
subject: 'Module m06_SAD',
|
26
|
+
text: message
|
27
|
+
}
|
28
|
+
|
29
|
+
transporter.sendMail(mailOptions, (err, info) => {
|
30
|
+
err ? console.log(err) : console.log('Sent: ' + info.response);
|
31
|
+
})
|
32
|
+
}
|
33
|
+
|
34
|
+
module.exports = send;
|
package/package.json
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
{
|
2
|
+
"dependencies": {
|
3
|
+
"nodemailer": "^6.9.7"
|
4
|
+
},
|
5
|
+
"name": "sadlab05",
|
6
|
+
"version": "1.0.0",
|
7
|
+
"main": "m06_SAD.js",
|
8
|
+
"devDependencies": {},
|
9
|
+
"scripts": {
|
10
|
+
"test": "test"
|
11
|
+
},
|
12
|
+
"repository": {
|
13
|
+
"type": "git",
|
14
|
+
"url": "git"
|
15
|
+
},
|
16
|
+
"author": "",
|
17
|
+
"license": "ISC",
|
18
|
+
"description": ""
|
19
|
+
}
|