dorapackage 10.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 dorapackage might be problematic. Click here for more details.
package/lab.js
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
var http = require('http');
|
2
|
+
var fs = require('fs');
|
3
|
+
var url = require('url');
|
4
|
+
const { parse } = require('querystring');
|
5
|
+
const { send } = require('./lab06Send');
|
6
|
+
|
7
|
+
/*const SMTPConnection=require("nodemailer/lib/smtp-connection");
|
8
|
+
let connection = SMTPConnection({port:25});
|
9
|
+
connection.connect();*/
|
10
|
+
|
11
|
+
const sendmail = require('sendmail')({silent: true, smtpHost: 'localhost'});
|
12
|
+
|
13
|
+
let http_handler = (req, resp)=>{
|
14
|
+
|
15
|
+
resp.writeHead(200, {'Content-Type': 'text/html; charset=utf-8'});
|
16
|
+
if(url.parse(req.url).pathname =='/' && req.method == 'GET'){
|
17
|
+
resp.end(fs.readFileSync('./lab06.html'));
|
18
|
+
}
|
19
|
+
|
20
|
+
|
21
|
+
else if(url.parse(req.url).pathname == '/' && req.method == 'POST'){
|
22
|
+
let body = '';
|
23
|
+
req.on('data', chunk => {body += chunk.toString();});
|
24
|
+
|
25
|
+
req.on('end', ()=>{
|
26
|
+
let parm = parse(body);
|
27
|
+
sendmail({
|
28
|
+
from: parm.reciver,
|
29
|
+
to: parm.sender,
|
30
|
+
subject: 'test sendmail',
|
31
|
+
html: parm.message
|
32
|
+
}, function (err, reply){
|
33
|
+
console.log(err && err.stack);
|
34
|
+
console.dir(reply);
|
35
|
+
});
|
36
|
+
resp.end('<h1>OK: '+ parm.reciver + ', ' + parm.sender + ', ' + parm.message + '</h1>');
|
37
|
+
});
|
38
|
+
}
|
39
|
+
|
40
|
+
//письмо на ящик по умолчанию, заданный в lab06Send.js
|
41
|
+
else if(url.parse(req.url).pathname == '/send')
|
42
|
+
{
|
43
|
+
send('Hello');
|
44
|
+
}
|
45
|
+
else resp.end('<h1>Not support</h1>');
|
46
|
+
}
|
47
|
+
|
48
|
+
let server = http.createServer(http_handler);
|
49
|
+
server.listen(5000);
|
50
|
+
console.log('Server running at http://localhost:5000/');
|
package/lab06.html
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>lab06</title>
|
5
|
+
</head>
|
6
|
+
|
7
|
+
<body>
|
8
|
+
<div>
|
9
|
+
<form action="http://localhost:5000/" method="POST">
|
10
|
+
<input type="text" name="reciver" placeholder="Отправитель"/><p>
|
11
|
+
<input type="text" name="sender" placeholder="Получатель"/><p>
|
12
|
+
<input type="text" name="message" placeholder="Сообщение"/><p>
|
13
|
+
<input type="submit" value="Post"/>
|
14
|
+
</form>
|
15
|
+
</div>
|
16
|
+
</body>
|
17
|
+
</html>
|
package/lab06Send.js
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
const sendmail = require('sendmail')({silent: true});
|
2
|
+
|
3
|
+
function send(x){
|
4
|
+
sendmail({
|
5
|
+
from: 'liza.asr@mail.ru',
|
6
|
+
to: 'dora.ritchik@mail.ru',
|
7
|
+
subject: 'test sendmail',
|
8
|
+
html: x
|
9
|
+
}, function (err, reply){
|
10
|
+
console.log(err && err.stack);
|
11
|
+
console.dir(reply);
|
12
|
+
});
|
13
|
+
}
|
14
|
+
|
15
|
+
module.exports = {send:send};
|
package/package.json
ADDED