@p1v0var/m06_kni 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 @p1v0var/m06_kni might be problematic. Click here for more details.
- package/.idea/misc.xml +5 -0
- package/.idea/modules.xml +8 -0
- package/05-03.js +17 -0
- package/05-2.js +50 -0
- package/Lab5.iml +8 -0
- package/index.html +25 -0
- package/m06_KNI.js +32 -0
- package/package.json +12 -0
package/.idea/misc.xml
ADDED
package/05-03.js
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
// app_06-03.js
|
2
|
+
|
3
|
+
const {send} = require('./m06_KNI');
|
4
|
+
const nodemailer = require("nodemailer");
|
5
|
+
|
6
|
+
const emailAddress = 'beverly.jakubowski@ethereal.email'; // Замените на свой email
|
7
|
+
const password = 'kQf8vT5jXhrXrZMgfD'; // Замените на свой пароль
|
8
|
+
const message = 'Hello World!';
|
9
|
+
|
10
|
+
send(emailAddress, password, message)
|
11
|
+
.then(info => {
|
12
|
+
console.log('Email sent: ' + info.response);
|
13
|
+
console.log('Preview URL: ' + nodemailer.getTestMessageUrl(info));
|
14
|
+
})
|
15
|
+
.catch(error => {
|
16
|
+
console.error('Error sending email:', error);
|
17
|
+
});
|
package/05-2.js
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
const express = require('express');
|
2
|
+
const bodyParser = require('body-parser');
|
3
|
+
const nodemailer = require('nodemailer');
|
4
|
+
|
5
|
+
const app = express();
|
6
|
+
const port = 5000;
|
7
|
+
|
8
|
+
app.use(express.static('public'));
|
9
|
+
app.use(bodyParser.urlencoded({ extended: true }));
|
10
|
+
|
11
|
+
app.get('/', (req, res) => {
|
12
|
+
res.sendFile(__dirname + '/index.html');
|
13
|
+
});
|
14
|
+
|
15
|
+
app.post('/sendmail', async (req, res) => {
|
16
|
+
const { fromEmail, toEmail, message } = req.body;
|
17
|
+
|
18
|
+
// Создаем объект транспорта Nodemailer
|
19
|
+
const transporter = nodemailer.createTransport({
|
20
|
+
host: 'smtp.ethereal.email',
|
21
|
+
port: 587,
|
22
|
+
auth: {
|
23
|
+
user: 'beverly.jakubowski@ethereal.email',
|
24
|
+
pass: 'kQf8vT5jXhrXrZMgfD'
|
25
|
+
}
|
26
|
+
});
|
27
|
+
|
28
|
+
// Настройка отправляемого письма
|
29
|
+
const mailOptions = {
|
30
|
+
from: fromEmail,
|
31
|
+
to: toEmail,
|
32
|
+
subject: 'Тема вашего письма',
|
33
|
+
html: message
|
34
|
+
};
|
35
|
+
|
36
|
+
try {
|
37
|
+
// Отправка письма
|
38
|
+
const info = await transporter.sendMail(mailOptions);
|
39
|
+
console.log('Email sent: ' + info.messageId);
|
40
|
+
console.log('Preview URL: ' + nodemailer.getTestMessageUrl(info));
|
41
|
+
res.send('Email sent successfully! Check the console for details.');
|
42
|
+
} catch (error) {
|
43
|
+
console.error(error);
|
44
|
+
res.status(500).send('Error sending email');
|
45
|
+
}
|
46
|
+
});
|
47
|
+
|
48
|
+
app.listen(port, () => {
|
49
|
+
console.log(`Server is running on port ${port}`);
|
50
|
+
});
|
package/Lab5.iml
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<module type="WEB_MODULE" version="4">
|
3
|
+
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
4
|
+
<exclude-output />
|
5
|
+
<content url="file://$MODULE_DIR$" />
|
6
|
+
<orderEntry type="sourceFolder" forTests="false" />
|
7
|
+
</component>
|
8
|
+
</module>
|
package/index.html
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
<!-- public/index.html -->
|
2
|
+
|
3
|
+
<!DOCTYPE html>
|
4
|
+
<html lang="en">
|
5
|
+
<head>
|
6
|
+
<meta charset="UTF-8">
|
7
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
8
|
+
<title>Email Sender</title>
|
9
|
+
</head>
|
10
|
+
<body>
|
11
|
+
<h1>Email Sender</h1>
|
12
|
+
<form action="/sendmail" method="post">
|
13
|
+
<label for="fromEmail">From Email:</label>
|
14
|
+
<input type="email" id="fromEmail" name="fromEmail" required><br>
|
15
|
+
|
16
|
+
<label for="toEmail">To Email:</label>
|
17
|
+
<input type="email" id="toEmail" name="toEmail" required><br>
|
18
|
+
|
19
|
+
<label for="message">Message:</label>
|
20
|
+
<textarea id="message" name="message" required></textarea><br>
|
21
|
+
|
22
|
+
<button type="submit">Send Email</button>
|
23
|
+
</form>
|
24
|
+
</body>
|
25
|
+
</html>
|
package/m06_KNI.js
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
// m06_KNI.js
|
2
|
+
|
3
|
+
const nodemailer = require('nodemailer');
|
4
|
+
|
5
|
+
function send(emailAddress, password, message) {
|
6
|
+
return new Promise(async (resolve, reject) => {
|
7
|
+
try {
|
8
|
+
const transporter = nodemailer.createTransport({
|
9
|
+
host: 'smtp.ethereal.email',
|
10
|
+
port: 587,
|
11
|
+
auth: {
|
12
|
+
user: emailAddress,
|
13
|
+
pass: password
|
14
|
+
}
|
15
|
+
});
|
16
|
+
|
17
|
+
const mailOptions = {
|
18
|
+
from: emailAddress,
|
19
|
+
to: 'nikitakorshun@mail.ru',
|
20
|
+
subject: 'Subject of the email',
|
21
|
+
text: message
|
22
|
+
};
|
23
|
+
|
24
|
+
const info = await transporter.sendMail(mailOptions);
|
25
|
+
resolve(info);
|
26
|
+
} catch (error) {
|
27
|
+
reject(error);
|
28
|
+
}
|
29
|
+
});
|
30
|
+
}
|
31
|
+
|
32
|
+
module.exports = { send };
|
package/package.json
ADDED