m0504test 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
package/05-02.html ADDED
@@ -0,0 +1,80 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+
4
+ <head>
5
+ <meta charset="UTF-8">
6
+ <style type="text/css">
7
+ .senderRecieverWrapper {
8
+ display: flex;
9
+ gap: 10%
10
+ }
11
+
12
+ .senderWrapper {
13
+ display: flex;
14
+ flex-direction: column;
15
+ }
16
+
17
+ .spaceBetween {
18
+ display: flex;
19
+ justify-content: space-between;
20
+ }
21
+ </style>
22
+
23
+ </head>
24
+
25
+
26
+
27
+ <body>
28
+ <div id="container">
29
+ <form action="http://localhost:5000/" method="POST">
30
+ <div id="container_table">
31
+ <div class="senderRecieverWrapper">
32
+ <div class="senderWrapper">
33
+ <div class="spaceBetween">
34
+ <td>Отправитель</td>
35
+ <td><input id="sender" type="email" name="sender" placeholder="Ваш e-mail"
36
+ value="danik2003globin@gmail.com"></td>
37
+ </div>
38
+
39
+ <div class="spaceBetween">
40
+ <td>Пароль</td>
41
+ <td><input id="password" type="password" name="password" placeholder="Ваш пароль"
42
+ value="elbi xpzh tpem ovxo"></td>
43
+ </div>
44
+ </div>
45
+
46
+
47
+ <div class="recieverWrapper">
48
+ <td>Получатель</td>
49
+ <td><input id="receiver" type="email" name="receiver" placeholder="E-mail получателя"
50
+ value="danila.kozlyakovsky@truesolv.com"></td>
51
+ </div>
52
+ </div>
53
+
54
+ <br>
55
+ <br>
56
+
57
+ <div class="spaceBetween" style="width: 40%;">
58
+ <td>Тема</td>
59
+ <td><input id="subject" type="text" name="subject" placeholder="Тема сообщения"
60
+ value="пытаюсь сдать 5 лабу по node.js"></td>
61
+ </div>
62
+
63
+ <div class="spaceBetween" style="width: 40%;">
64
+ <td>Сообщение</td>
65
+ <td><input id=" message" type="text" name="message" placeholder="Ваше сообщение"
66
+ value="После лабы поешь супа">
67
+ </td>
68
+ </div>
69
+ </div>
70
+
71
+ <br>
72
+ <br>
73
+
74
+ <button type="submit">Отправить</button>
75
+ </form>
76
+ </div>
77
+
78
+ </body>
79
+
80
+ </html>
package/05-02.js ADDED
@@ -0,0 +1,65 @@
1
+ // import http from 'http';
2
+ // import url from 'url';
3
+ // import fs from 'fs';
4
+ // import { parse } from 'querystring';
5
+ // import nodemailer from 'nodemailer';
6
+ // to use imports instead of require, open package.json
7
+ // and add "type": "module", before "dependencies"
8
+ // xbguckzhonlehivd
9
+
10
+
11
+
12
+ const http = require('http');
13
+ const url = require('url');
14
+ const fs = require('fs');
15
+ const { parse } = require('querystring');
16
+ const nodemailer = require('nodemailer');
17
+
18
+
19
+
20
+ http.createServer((request, response) => {
21
+ response.writeHead(200, { 'Content-Type': 'text/html; charset=utf-8' });
22
+
23
+ if (url.parse(request.url).pathname === '/' && request.method === 'GET') {
24
+ response.end(fs.readFileSync('./05-02.html'));
25
+ }
26
+ else if (url.parse(request.url).pathname === '/' && request.method === 'POST') {
27
+ let body = '';
28
+ request.on('data', chunk => { body += chunk.toString(); });
29
+
30
+ request.on('end', () => {
31
+ let parm = parse(body);
32
+
33
+ const transporter = nodemailer.createTransport({
34
+ host: 'smtp.gmail.com',
35
+ port: 465,
36
+ secure: false,
37
+ service: 'Gmail',
38
+ auth: {
39
+ user: parm.sender,
40
+ pass: parm.password
41
+ }
42
+ });
43
+
44
+ const mailOptions = {
45
+ from: parm.sender,
46
+ to: parm.receiver,
47
+ subject: parm.subject,
48
+ text: parm.message
49
+ }
50
+
51
+ transporter.sendMail(mailOptions, (err, info) => {
52
+ err ? console.log(err) : console.log('Sent: ' + info.response);
53
+ })
54
+
55
+ response.end(`<h2>Отправитель: ${parm.sender}</br>Получатель: ${parm.receiver}
56
+ </br>Тема: ${parm.subject}</br>Сообщение: ${parm.message}</h2>`);
57
+ })
58
+ }
59
+
60
+ else
61
+ response.end('<html><body><h1>Error! Visit localhost:5000/</h1></body></html>');
62
+ }).listen(5000, () => console.log('Server running at localhost:5000/\n'));
63
+
64
+
65
+
package/05-03.js ADDED
@@ -0,0 +1,13 @@
1
+ const http = require('http');
2
+ const send = require('./m0503.js');
3
+
4
+ const sender = 'danik2003globin@gmail.com';
5
+ const receiver = 'danik2003globin@gmail.com';
6
+ const password = 'elbi xpzh tpem ovxo';
7
+ const message = '[05-03] Hello World!!!';
8
+
9
+ http.createServer((request, response) => {
10
+ response.writeHead(200, { 'Content-Type': 'text/html; charset=utf-8' });
11
+ send(receiver, sender, password, message);
12
+ response.end('<h2>Message sucessfully sent.</h2>');
13
+ }).listen(5000, () => console.log('Server running at localhost:5000/\n'));
package/05-04.js ADDED
@@ -0,0 +1,15 @@
1
+ // 'D:\\3k1s\\MyLabs\\PSCA\\5\\PSKP_Lab5\\node_modules\\m0504\\m0503.js'
2
+ // `C:\\Program Files\\nodejs\\node_modules\\m0504\\m0503.js`
3
+ const send = require('C:\\Program Files\\nodejs\\node_modules\\m0504\\m0503.js');
4
+ const http = require('http');
5
+
6
+ const sender = 'danik2003globin@gmail.com';
7
+ const receiver = 'danik2003globin@gmail.com';
8
+ const password = 'elbi xpzh tpem ovxo';
9
+ const message = '[05-03] Hello World!!!';
10
+
11
+ http.createServer((request, response) => {
12
+ response.writeHead(200, { 'Content-Type': 'text/html; charset=utf-8' });
13
+ send(receiver, sender, password, message);
14
+ response.end('<h2>Message sucessfully sent.</h2>');
15
+ }).listen(5000, () => console.log('Server running at localhost:5000/\n'));
File without changes
package/m0503.js ADDED
@@ -0,0 +1,28 @@
1
+ const nodemailer = require('nodemailer');
2
+
3
+ send = (receiver, sender, password, message) => {
4
+
5
+ const transporter = nodemailer.createTransport({
6
+ host: 'smtp.gmail.com',
7
+ port: 465,
8
+ secure: false,
9
+ service: 'Gmail',
10
+ auth: {
11
+ user: sender,
12
+ pass: password
13
+ }
14
+ });
15
+
16
+ const mailOptions = {
17
+ from: sender,
18
+ to: receiver,
19
+ subject: 'Module m0503',
20
+ text: message
21
+ }
22
+
23
+ transporter.sendMail(mailOptions, (err, info) => {
24
+ err ? console.log(err) : console.log('Sent: ' + info.response);
25
+ })
26
+ }
27
+
28
+ module.exports = send;
Binary file
Binary file
File without changes
Binary file
File without changes
package/npm root -g ADDED
File without changes
package/package.json ADDED
@@ -0,0 +1,7 @@
1
+ {
2
+ "name": "m0504test",
3
+ "version": "1.0.0",
4
+ "dependencies": {
5
+ "nodemailer": "^6.9.6"
6
+ }
7
+ }