lab05sol 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of lab05sol might be problematic. Click here for more details.
- package/05_02.html +35 -0
- package/05_02.js +64 -0
- package/05_03.js +8 -0
- package/05_04.js +9 -0
- package/m06_ZKM.js +35 -0
- package/package.json +19 -0
package/05_02.html
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<meta charset="UTF-8">
|
5
|
+
</head>
|
6
|
+
<body>
|
7
|
+
<div id="container">
|
8
|
+
<form action="http://localhost:5000/" method="POST">
|
9
|
+
<table id="container_table">
|
10
|
+
<tr>
|
11
|
+
<td>Отправитель</td>
|
12
|
+
<td><input id="sender" type="email" name="sender" placeholder="Ваш e-mail"></td>
|
13
|
+
</tr>
|
14
|
+
|
15
|
+
<tr>
|
16
|
+
<td>Получатель</td>
|
17
|
+
<td><input id="receiver" type="email" name="receiver" placeholder="E-mail получателя"></td>
|
18
|
+
</tr>
|
19
|
+
|
20
|
+
<tr>
|
21
|
+
<td>Тема</td>
|
22
|
+
<td><input id="subject" type="text" name="subject" placeholder="Тема сообщения"></td>
|
23
|
+
</tr>
|
24
|
+
|
25
|
+
<tr>
|
26
|
+
<td>Сообщение</td>
|
27
|
+
<td><input id="message" type="text" name="message" placeholder="Ваше сообщение"></td>
|
28
|
+
</tr>
|
29
|
+
</table>
|
30
|
+
<button type="submit">Отправить</button>
|
31
|
+
</form>
|
32
|
+
</div>
|
33
|
+
|
34
|
+
</body>
|
35
|
+
</html>
|
package/05_02.js
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
|
2
|
+
// информация о пакете nodemailer: npm info nodemailer
|
3
|
+
// установка: npm install nodemailer
|
4
|
+
// проверка установки: npm list nodemailer
|
5
|
+
|
6
|
+
const http = require('http');
|
7
|
+
const url = require('url');
|
8
|
+
const fs = require('fs');
|
9
|
+
const { parse } = require('querystring');
|
10
|
+
const nodemailer = require('nodemailer');
|
11
|
+
|
12
|
+
|
13
|
+
|
14
|
+
http.createServer((request, response) => {
|
15
|
+
response.writeHead(200, { 'Content-Type': 'text/html; charset=utf-8' });
|
16
|
+
|
17
|
+
if (url.parse(request.url).pathname === '/' && request.method === 'GET')
|
18
|
+
{
|
19
|
+
response.end(fs.readFileSync('./05_02.html'));
|
20
|
+
}
|
21
|
+
else if (url.parse(request.url).pathname === '/' && request.method === 'POST')
|
22
|
+
{
|
23
|
+
let body = '';
|
24
|
+
request.on('data', chunk => { body += chunk.toString(); });
|
25
|
+
|
26
|
+
request.on('end', () => {
|
27
|
+
let parm = parse(body);
|
28
|
+
const transporter = nodemailer.createTransport({
|
29
|
+
host: 'smtp.gmail.com',
|
30
|
+
port: 465,
|
31
|
+
secure: false,
|
32
|
+
service: 'Gmail',
|
33
|
+
auth: {
|
34
|
+
user: parm.sender,
|
35
|
+
pass: parm.password
|
36
|
+
}
|
37
|
+
});
|
38
|
+
|
39
|
+
const mailOptions = {
|
40
|
+
from: parm.sender,
|
41
|
+
to: parm.receiver,
|
42
|
+
subject: parm.subject,
|
43
|
+
text: parm.message
|
44
|
+
}
|
45
|
+
|
46
|
+
transporter.sendMail(mailOptions, (err, info) => {
|
47
|
+
err ? console.log(err) : console.log('Sent: ' + info.response);
|
48
|
+
})
|
49
|
+
|
50
|
+
response.end(`<h2>Отправитель: ${parm.sender}</br>Получатель: ${parm.receiver}
|
51
|
+
</br>Тема: ${parm.subject}</br>Сообщение: ${parm.message}</h2>`);
|
52
|
+
})
|
53
|
+
}
|
54
|
+
|
55
|
+
else
|
56
|
+
response.end('<html><body><h1>Error! Visit localhost:5000/</h1></body></html>');
|
57
|
+
}).listen(5000, () => console.log('Server running on http://localhost:5000/\n'));
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
|
64
|
+
|
package/05_03.js
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
const http = require('http');
|
2
|
+
const send = require('./m06_ZKM.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
|
+
// C:\Users\37544\AppData\Roaming\npm\node_modules\zam12345
|
2
|
+
const send = require("C:\\Users\\37544\\AppData\\Roaming\\npm\\node_modules\\zam12345");
|
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_ZKM.js
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
const nodemailer = require('nodemailer');
|
2
|
+
|
3
|
+
const sender = 'kseniazhuk84@gmail.com';
|
4
|
+
const receiver = 'kseniazhuk84@gmail.com';
|
5
|
+
const password = 'nojj nfum mcam lpbx';
|
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
|
+
|
23
|
+
const mailOptions = {
|
24
|
+
from: sender,
|
25
|
+
to: receiver,
|
26
|
+
subject: 'Module m06_ZKM',
|
27
|
+
text: message
|
28
|
+
}
|
29
|
+
|
30
|
+
transporter.sendMail(mailOptions, (err, info) => {
|
31
|
+
err ? console.log(err) : console.log('Sent: ' + info.response);
|
32
|
+
})
|
33
|
+
}
|
34
|
+
|
35
|
+
module.exports = send;
|
package/package.json
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
{
|
2
|
+
"dependencies": {
|
3
|
+
"nodemailer": "^6.9.7",
|
4
|
+
"soln123": "^1.0.0"
|
5
|
+
},
|
6
|
+
"name": "lab05sol",
|
7
|
+
"version": "1.0.0",
|
8
|
+
"description": "lab05",
|
9
|
+
"main": "m06_ZKM.js",
|
10
|
+
"scripts": {
|
11
|
+
"test": "test"
|
12
|
+
},
|
13
|
+
"repository": {
|
14
|
+
"type": "git",
|
15
|
+
"url": "git"
|
16
|
+
},
|
17
|
+
"author": "Zhuk Ksenia",
|
18
|
+
"license": "ISC"
|
19
|
+
}
|