@p1v0var/m06_kni 1.0.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of @p1v0var/m06_kni might be problematic. Click here for more details.

package/.idea/misc.xml ADDED
@@ -0,0 +1,5 @@
1
+ <project version="4">
2
+ <component name="ProjectRootManager">
3
+ <output url="file://$PROJECT_DIR$/out" />
4
+ </component>
5
+ </project>
@@ -0,0 +1,8 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="ProjectModuleManager">
4
+ <modules>
5
+ <module fileurl="file://$PROJECT_DIR$/Lab5.iml" filepath="$PROJECT_DIR$/Lab5.iml" />
6
+ </modules>
7
+ </component>
8
+ </project>
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
@@ -0,0 +1,12 @@
1
+ {
2
+ "name": "@p1v0var/m06_kni",
3
+ "version": "1.0.0",
4
+ "main": "m06_KNI.js",
5
+ "private": false,
6
+ "dependencies": {
7
+ "cors": "^2.8.5",
8
+ "express": "^4.18.2",
9
+ "nodemailer": "^6.9.6",
10
+ "nodemailer-direct-transport": "^3.3.2"
11
+ }
12
+ }