fdkhjrrsth 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
package/06-02.html ADDED
@@ -0,0 +1,44 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+
4
+ <head>
5
+ <meta charset="UTF-8">
6
+ </head>
7
+
8
+ <body>
9
+ <div id="container">
10
+ <form action="http://localhost:5000/" method="POST">
11
+ <table>
12
+ <tr>
13
+ <td>Sender</td>
14
+ <td><input id="sender" type="email" name="sender" placeholder="Enter your email"></td>
15
+ </tr>
16
+
17
+ <tr>
18
+ <td>Password</td>
19
+ <td><input id="password" type="password" name="password" placeholder="Enter password"></td>
20
+ </tr>
21
+
22
+ <tr>
23
+ <td>Receiver</td>
24
+ <td><input id="receiver" type="email" name="receiver" placeholder="Receiver email"></td>
25
+ </tr>
26
+
27
+ <tr>
28
+ <td>Subject</td>
29
+ <td><input id="subject" type="text" name="subject" placeholder="Enter subject"></td>
30
+ </tr>
31
+
32
+ <tr>
33
+ <td>Message</td>
34
+ <td><input id="message" type="text" name="message" placeholder="Your message"></td>
35
+ </tr>
36
+ </table>
37
+
38
+ <button type="submit">Send</button>
39
+ </form>
40
+ </div>
41
+
42
+ </body>
43
+
44
+ </html>
package/06-02.js ADDED
@@ -0,0 +1,52 @@
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.createServer((request, response) => {
8
+ response.writeHead(200, { 'Content-Type': 'text/html; charset=utf-8' });
9
+
10
+ if (url.parse(request.url).pathname === '/' && request.method === 'GET')
11
+ {
12
+ response.end(fs.readFileSync('./06-02.html'));
13
+ }
14
+ else if (url.parse(request.url).pathname === '/' && request.method === 'POST')
15
+ {
16
+ let body = '';
17
+ request.on('data', chunk => { body += chunk.toString(); });
18
+
19
+ request.on('end', () => {
20
+ let parm = parse(body);
21
+
22
+ const transporter = nodemailer.createTransport({
23
+ host: 'smtp.gmail.com',
24
+ port: 587,
25
+ ignoreTLS: false,
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>Sender: ${parm.sender}</br>Receiver: ${parm.receiver}
46
+ </br>Subject: ${parm.subject}</br>Message: ${parm.message}</h2>`);
47
+ })
48
+ }
49
+
50
+ else
51
+ response.end('<html><body><h1>localhost:5000/</h1></body></html>');
52
+ }).listen(5000, () => console.log('Server running at localhost:5000/\n'));
package/06-03.js ADDED
@@ -0,0 +1,8 @@
1
+ const http = require('http');
2
+ const send = require('./m0603');
3
+
4
+ http.createServer((req,res) => {
5
+ res.writeHead(200, {'Content-Type' : 'text/html; charset=utf-8'});
6
+ send('Hello from 06-03.js');
7
+ res.end('<h2>Success</h2>');
8
+ }).listen(5000, () => console.log('Server running at localhost:5000'));
package/m0603.js ADDED
@@ -0,0 +1,33 @@
1
+ const nodemailer = require('nodemailer');
2
+
3
+ const sender = 'gudevtechbot@gmail.com';
4
+ const receiver = 'gudevtechbot@gmail.com';
5
+ const password = 'uhmtabpcvqegenut';
6
+
7
+ const transporter = nodemailer.createTransport({
8
+ host: 'smtp.gmail.com',
9
+ port: 587,
10
+ ignoreTLS: false,
11
+ secure: false,
12
+ service: 'Gmail',
13
+ auth: {
14
+ user: sender,
15
+ pass: password
16
+ }
17
+ });
18
+
19
+ send = (message) =>
20
+ {
21
+ const mailOptions = {
22
+ from: sender,
23
+ to: receiver,
24
+ subject: 'this is a test',
25
+ text: message
26
+ }
27
+
28
+ transporter.sendMail(mailOptions, (err, info) =>{
29
+ err ? console.log(err) : console.log('Sent: ' + info.response);
30
+ })
31
+ }
32
+
33
+ module.exports = send;
package/package.json ADDED
@@ -0,0 +1,9 @@
1
+ {
2
+ "name": "fdkhjrrsth",
3
+ "version": "1.0.1",
4
+ "description": "lab6",
5
+ "keyword" : "message sender",
6
+ "main": "m0603.js",
7
+ "author": "wxxzzzyyyy",
8
+ "publishConfig": {"access": "public"}
9
+ }