m0603mike 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.
package/06-02.js ADDED
@@ -0,0 +1,72 @@
1
+ // Информация о пакете
2
+ // npm view nodemailer;
3
+ // npm info nodemailer;
4
+
5
+ // Установка пакета
6
+ // npm install nodemailer; - локально
7
+ // npm insatall -g nodemailer - глобально
8
+
9
+ // Проверка установлен ли пакет
10
+ // npm -v nodemailer
11
+ // Проверить зависимости в package.json
12
+
13
+ const {mailF} = require("./m0603");
14
+ const http = require("http");
15
+ const fs = require("fs");
16
+
17
+
18
+ const nodeMailer = require("nodemailer");
19
+ function Mail(from,to,message) {
20
+
21
+ let transporter = nodeMailer.createTransport({
22
+ host: 'smtp.mail.ru',
23
+ port: 465,
24
+ secure: true,
25
+ auth: {
26
+ user: from,
27
+ pass: 'fA9wAJg8qEUmhTsnTe42'
28
+ }
29
+ });
30
+ // 'bstulearning@mail.ru'
31
+
32
+ let mailOptions = {
33
+ from: from,
34
+ to: to,
35
+ subject: 'Пересылка',
36
+ text: message,
37
+
38
+ };
39
+
40
+ transporter.sendMail(mailOptions, (error, info) => {
41
+ if (error) {
42
+ return console.log(error);
43
+ }
44
+ console.log('Message %s sent: %s', info.messageId, info.response);
45
+ res.render('index');
46
+ });
47
+ }
48
+
49
+
50
+ let block;
51
+ http.createServer((req, res)=>{
52
+ let data = fs.readFileSync("index.html",'utf-8');
53
+ if(req.url == "/"){
54
+ res.end(data);
55
+ }
56
+ if(req.method == "POST"){
57
+ if(req.url == '/send-email'){
58
+
59
+ req.on('data', (data)=>{
60
+ block = JSON.parse(data);
61
+ from = block.from;
62
+ to = block.toOne;
63
+ mesage = block.message;
64
+ Mail(from,to,mesage);
65
+ });
66
+ }
67
+ }
68
+ }).listen(5000, '127.0.0.1', ()=> {
69
+ console.log("Сервер запущен!");
70
+ });
71
+
72
+
package/06-03.js ADDED
@@ -0,0 +1,30 @@
1
+ const {mailF} = require("./m0603");
2
+ const http = require("http");
3
+ const fs = require("fs");
4
+
5
+
6
+ let block;
7
+ http.createServer((req, res)=>{
8
+ let data = fs.readFileSync("index.html",'utf-8');
9
+ if(req.url == "/"){
10
+ res.end(data);
11
+ }
12
+ if(req.method == "POST"){
13
+ if(req.url == '/send-email'){
14
+
15
+ req.on('data', (data)=>{
16
+ block = JSON.parse(data);
17
+ from = block.from;
18
+ to = block.toOne;
19
+ mesage = block.message;
20
+ mailF(from,to,mesage);
21
+ });
22
+
23
+
24
+ }
25
+ }
26
+ }).listen(5000, '127.0.0.1', ()=> {
27
+ console.log("Сервер запущен!");
28
+ });
29
+
30
+
package/index.html ADDED
@@ -0,0 +1,36 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta http-equiv="X-UA-Compatible" content="IE=edge">
6
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
7
+ <title>Document</title>
8
+ </head>
9
+ <body>
10
+ <form method="post">
11
+ <h1> Форма пересылки сообщения </h1>
12
+ <h2>Введите адрес отправителя</h2>
13
+ <input id="from" name="from" type="text"/>
14
+ <h2>Введите адрес получателя</h2>
15
+ <input id="toOne" name="to" type="text"/>
16
+ <h2>Введите сообщение для пересылки</h2>
17
+ <input id="message" name="message" type="text"/>
18
+ <button id="send" type="submit" onclick="Post();" > Отправить</button>
19
+ </form>
20
+
21
+ <script>
22
+
23
+ function Post() {
24
+
25
+ fetch( '/send-email', {
26
+ method: 'POST', mode: 'no-cors',
27
+ headers: {'Content-Type': 'application/json', 'Accept':'application/json'},
28
+ body: JSON.stringify({from: from.value, toOne: toOne.value, message: message.value})
29
+ })
30
+ .then(response => response.json())
31
+
32
+ }
33
+
34
+ </script>
35
+ </body>
36
+ </html>
package/m0603.js ADDED
@@ -0,0 +1,33 @@
1
+
2
+ const nodeMailer = require("nodemailer");
3
+
4
+ module.exports.mailF = function(from,to,message) {
5
+
6
+ let transporter = nodeMailer.createTransport({
7
+ host: 'smtp.mail.ru',
8
+ port: 465,
9
+ secure: true,
10
+ auth: {
11
+ user: from,
12
+ pass: 'fA9wAJg8qEUmhTsnTe42'
13
+ }
14
+ });
15
+ // 'bstulearning@mail.ru'
16
+
17
+ let mailOptions = {
18
+ from: from,
19
+ to: to,
20
+ subject: 'Пересылка',
21
+ text: message,
22
+
23
+ };
24
+
25
+ transporter.sendMail(mailOptions, (error, info) => {
26
+ if (error) {
27
+ return console.log(error);
28
+ }
29
+ console.log('Message %s sent: %s', info.messageId, info.response);
30
+ res.render('index');
31
+ });
32
+ }
33
+
package/package.json ADDED
@@ -0,0 +1,16 @@
1
+ {
2
+ "dependencies": {
3
+ "nodemailer": "^6.9.1"
4
+ },
5
+
6
+ "name": "m0603mike",
7
+ "version": "1.0.0",
8
+ "main": "06-02.js",
9
+ "devDependencies": {},
10
+ "scripts": {
11
+ "test": "echo \"Error: no test specified\" && exit 1"
12
+ },
13
+ "author": "",
14
+ "license": "ISC",
15
+ "description": ""
16
+ }