shakhlai_lab6 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of shakhlai_lab6 might be problematic. Click here for more details.
- package/06-02.html +107 -0
- package/06-02.js +55 -0
- package/06-03.js +10 -0
- package/06-04.js +10 -0
- package/m0603.js +31 -0
- package/package.json +15 -0
package/06-02.html
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html>
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8" />
|
|
5
|
+
<style type="text/css">
|
|
6
|
+
* {
|
|
7
|
+
font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
|
|
8
|
+
Roboto, Oxygen, Ubuntu, Cantarell, "Open Sans", "Helvetica Neue",
|
|
9
|
+
sans-serif;
|
|
10
|
+
font-size: 18px;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
input {
|
|
14
|
+
height: 32px;
|
|
15
|
+
width: 250px;
|
|
16
|
+
border: 1px solid #dbdbdb;
|
|
17
|
+
border-radius: 4px;
|
|
18
|
+
padding: 5px;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
button {
|
|
22
|
+
height: 2em;
|
|
23
|
+
font-size: 1rem;
|
|
24
|
+
background-color: rgb(248, 248, 248);
|
|
25
|
+
color: #2f2f2f;
|
|
26
|
+
border: 1px solid #c4c4c4;
|
|
27
|
+
border-radius: 4px;
|
|
28
|
+
margin: 10px 10px;
|
|
29
|
+
cursor: pointer;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
td {
|
|
33
|
+
padding: 12px 10px;
|
|
34
|
+
}
|
|
35
|
+
</style>
|
|
36
|
+
</head>
|
|
37
|
+
|
|
38
|
+
<body>
|
|
39
|
+
<div id="container">
|
|
40
|
+
<form action="http://localhost:5000/" method="POST">
|
|
41
|
+
<table id="container_table">
|
|
42
|
+
<tr>
|
|
43
|
+
<td>Отправитель</td>
|
|
44
|
+
<td>
|
|
45
|
+
<input
|
|
46
|
+
id="sender"
|
|
47
|
+
type="email"
|
|
48
|
+
name="sender"
|
|
49
|
+
placeholder="Ваш e-mail"
|
|
50
|
+
/>
|
|
51
|
+
</td>
|
|
52
|
+
</tr>
|
|
53
|
+
|
|
54
|
+
<tr>
|
|
55
|
+
<td>Пароль</td>
|
|
56
|
+
<td>
|
|
57
|
+
<input
|
|
58
|
+
id="password"
|
|
59
|
+
type="password"
|
|
60
|
+
name="password"
|
|
61
|
+
placeholder="Ваш пароль"
|
|
62
|
+
/>
|
|
63
|
+
</td>
|
|
64
|
+
</tr>
|
|
65
|
+
|
|
66
|
+
<tr>
|
|
67
|
+
<td>Получатель</td>
|
|
68
|
+
<td>
|
|
69
|
+
<input
|
|
70
|
+
id="receiver"
|
|
71
|
+
type="email"
|
|
72
|
+
name="receiver"
|
|
73
|
+
placeholder="E-mail получателя"
|
|
74
|
+
/>
|
|
75
|
+
</td>
|
|
76
|
+
</tr>
|
|
77
|
+
|
|
78
|
+
<tr>
|
|
79
|
+
<td>Тема</td>
|
|
80
|
+
<td>
|
|
81
|
+
<input
|
|
82
|
+
id="subject"
|
|
83
|
+
type="text"
|
|
84
|
+
name="subject"
|
|
85
|
+
placeholder="Тема сообщения"
|
|
86
|
+
/>
|
|
87
|
+
</td>
|
|
88
|
+
</tr>
|
|
89
|
+
|
|
90
|
+
<tr>
|
|
91
|
+
<td>Сообщение</td>
|
|
92
|
+
<td>
|
|
93
|
+
<input
|
|
94
|
+
id="message"
|
|
95
|
+
type="text"
|
|
96
|
+
name="message"
|
|
97
|
+
placeholder="Ваше сообщение"
|
|
98
|
+
/>
|
|
99
|
+
</td>
|
|
100
|
+
</tr>
|
|
101
|
+
</table>
|
|
102
|
+
|
|
103
|
+
<button type="submit">Отправить</button>
|
|
104
|
+
</form>
|
|
105
|
+
</div>
|
|
106
|
+
</body>
|
|
107
|
+
</html>
|
package/06-02.js
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
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
|
+
http
|
|
8
|
+
.createServer((request, response) => {
|
|
9
|
+
response.writeHead(200, { "Content-Type": "text/html; charset=utf-8" });
|
|
10
|
+
|
|
11
|
+
if (url.parse(request.url).pathname === "/" && request.method === "GET") {
|
|
12
|
+
response.end(fs.readFileSync("./06-02.html"));
|
|
13
|
+
} else if (
|
|
14
|
+
url.parse(request.url).pathname === "/" &&
|
|
15
|
+
request.method === "POST"
|
|
16
|
+
) {
|
|
17
|
+
let body = "";
|
|
18
|
+
request.on("data", (chunk) => {
|
|
19
|
+
body += chunk.toString();
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
request.on("end", () => {
|
|
23
|
+
let parm = parse(body);
|
|
24
|
+
|
|
25
|
+
const transporter = nodemailer.createTransport({
|
|
26
|
+
host: "smtp.gmail.com",
|
|
27
|
+
port: 465,
|
|
28
|
+
secure: false,
|
|
29
|
+
service: "Gmail",
|
|
30
|
+
auth: {
|
|
31
|
+
user: parm.sender,
|
|
32
|
+
pass: parm.password,
|
|
33
|
+
},
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
const mailOptions = {
|
|
37
|
+
from: parm.sender,
|
|
38
|
+
to: parm.receiver,
|
|
39
|
+
subject: parm.subject,
|
|
40
|
+
text: parm.message,
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
transporter.sendMail(mailOptions, (err, info) => {
|
|
44
|
+
err ? console.log(err) : console.log("Sent: " + info.response);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
response.end(`<h2>Отправитель: ${parm.sender}</br>Получатель: ${parm.receiver}
|
|
48
|
+
</br>Тема: ${parm.subject}</br>Сообщение: ${parm.message}</h2>`);
|
|
49
|
+
});
|
|
50
|
+
} else
|
|
51
|
+
response.end(
|
|
52
|
+
"<html><body><h1>Error! Visit localhost:5000/</h1></body></html>"
|
|
53
|
+
);
|
|
54
|
+
})
|
|
55
|
+
.listen(5000, () => console.log("Server running at localhost:5000/\n"));
|
package/06-03.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
const http = require("http");
|
|
2
|
+
const send = require("./m0603.js");
|
|
3
|
+
|
|
4
|
+
http
|
|
5
|
+
.createServer((request, response) => {
|
|
6
|
+
response.writeHead(200, { "Content-Type": "text/html; charset=utf-8" });
|
|
7
|
+
send("Всем привет");
|
|
8
|
+
response.end("<h2>Message sucessfully sent.</h2>");
|
|
9
|
+
})
|
|
10
|
+
.listen(5000, () => console.log("Server running at localhost:5000/\n"));
|
package/06-04.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
const send = require("C:/Users/valda/AppData/Roaming/npm/node_modules/secxmail");
|
|
2
|
+
const http = require("http");
|
|
3
|
+
|
|
4
|
+
http
|
|
5
|
+
.createServer((req, res) => {
|
|
6
|
+
res.writeHead(200, { "Content-Type": "text/html; charset=utf-8" });
|
|
7
|
+
send(" Это shakhlai_lab6 модуль!");
|
|
8
|
+
res.end("<h2>Сообщение отправлено.</h2>");
|
|
9
|
+
})
|
|
10
|
+
.listen(5000, () => console.log("Server running at localhost:5000/\n"));
|
package/m0603.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
const nodemailer = require("nodemailer");
|
|
2
|
+
|
|
3
|
+
const sender = "vika.shakhlai@gmail.com";
|
|
4
|
+
const receiver = "vika.shakhlai@gmail.com";
|
|
5
|
+
const password = "mvfzolxepuvucdar";
|
|
6
|
+
|
|
7
|
+
const transporter = nodemailer.createTransport({
|
|
8
|
+
host: "smtp.gmail.com",
|
|
9
|
+
port: 465,
|
|
10
|
+
secure: false,
|
|
11
|
+
service: "Gmail",
|
|
12
|
+
auth: {
|
|
13
|
+
user: sender,
|
|
14
|
+
pass: password,
|
|
15
|
+
},
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
send = (message) => {
|
|
19
|
+
const mailOptions = {
|
|
20
|
+
from: sender,
|
|
21
|
+
to: receiver,
|
|
22
|
+
subject: "Module m0306",
|
|
23
|
+
text: message,
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
transporter.sendMail(mailOptions, (err, info) => {
|
|
27
|
+
err ? console.log(err) : console.log("Sent: " + info.response);
|
|
28
|
+
});
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
module.exports = send;
|
package/package.json
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"dependencies": {
|
|
3
|
+
"nodemailer": "^6.8.0"
|
|
4
|
+
},
|
|
5
|
+
"name": "shakhlai_lab6",
|
|
6
|
+
"version": "1.0.0",
|
|
7
|
+
"description": "this 6lab for node.js",
|
|
8
|
+
"main": "06-02.js",
|
|
9
|
+
"devDependencies": {},
|
|
10
|
+
"scripts": {
|
|
11
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
12
|
+
},
|
|
13
|
+
"author": "v.shakhlai",
|
|
14
|
+
"license": "ISC"
|
|
15
|
+
}
|