abobam0603 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
package/m0603.js ADDED
@@ -0,0 +1,30 @@
1
+ const nodemailer = require('nodemailer');
2
+
3
+ function send(from, password, to, message) {
4
+ let transporter = nodemailer.createTransport({
5
+ host: "smtp.mail.ru",
6
+ port: 465,
7
+ secure: true,
8
+ auth: {
9
+ user: from,
10
+ pass: password
11
+ }
12
+ });
13
+
14
+ let mailOptions = {
15
+ from: from,
16
+ to: to,
17
+ subject: 'Message from m0603 module',
18
+ text: message
19
+ };
20
+
21
+ transporter.sendMail(mailOptions, (error, info) => {
22
+ if (error) {
23
+ console.log(error);
24
+ } else {
25
+ console.log('Message sent: %s', info.messageId);
26
+ }
27
+ });
28
+ }
29
+
30
+ module.exports = { send };
package/package.json ADDED
@@ -0,0 +1,18 @@
1
+ {
2
+ "name": "abobam0603",
3
+ "version": "1.0.0",
4
+ "description": "m0603 package for sending message through nodemailer",
5
+ "main": "m0603.js",
6
+ "scripts": {
7
+ "test": "echo \"Error: no test specified\" && exit 1"
8
+ },
9
+ "keywords": [],
10
+ "author": "potatorb",
11
+ "license": "ISC",
12
+ "dependencies": {
13
+ "express": "^4.18.2",
14
+ "m0603_adam": "^1.0.0",
15
+ "nodemailer": "^6.9.1"
16
+ },
17
+ "devDependencies": {}
18
+ }
package/task1.js ADDED
@@ -0,0 +1,3 @@
1
+ // 1. npm view nodemailer
2
+ // 2. npm install nodemailer
3
+ // 3. npm ls nodemailer
package/task2.html ADDED
@@ -0,0 +1,81 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Send Email</title>
5
+ <style>
6
+ body {
7
+ font-family: Arial, sans-serif;
8
+ font-size: 16px;
9
+ }
10
+
11
+ .container {
12
+ max-width: 600px;
13
+ margin: 0 auto;
14
+ text-align: center;
15
+ }
16
+
17
+ h1 {
18
+ color: #333;
19
+ font-size: 28px;
20
+ }
21
+
22
+ form {
23
+ display: flex;
24
+ flex-direction: column;
25
+ }
26
+
27
+ label {
28
+ display: inline-block;
29
+ width: 100px;
30
+ text-align: left;
31
+ }
32
+
33
+ input[type="email"], input[type="text"], textarea {
34
+ width: 100%;
35
+ padding: 10px;
36
+ border: 1px solid #ccc;
37
+ border-radius: 5px;
38
+ box-sizing: border-box;
39
+ }
40
+
41
+ textarea {
42
+ height: 100px;
43
+ }
44
+
45
+ button[type="submit"] {
46
+ background-color: #4CAF50;
47
+ color: white;
48
+ padding: 12px 20px;
49
+ border: none;
50
+ border-radius: 4px;
51
+ cursor: pointer;
52
+ font-size: 16px;
53
+ }
54
+
55
+ button[type="submit"]:hover {
56
+ background-color: #45a049;
57
+ }
58
+ </style>
59
+ </head>
60
+ <body>
61
+ <div class="container">
62
+ <h1>Send Email</h1>
63
+ <form method="post" action="/send">
64
+
65
+ <label for="from">From:</label>
66
+ <input type="email" id="from" name="from" value="andrei_sml@bk.ru" required><br><br>
67
+
68
+ <label for="to">To:</label>
69
+ <input type="email" id="to" name="to" value="andrei.uiu.uiu@gmail.com" required><br><br>
70
+
71
+ <label for="subject">Subject:</label>
72
+ <input type="text" id="subject" name="subject" value="ururururuurururuuru" required><br><br>
73
+
74
+ <label for="message">Message:</label><br>
75
+ <textarea id="message" name="message" rows="10" value="Aboba Dominatus" cols="30" required></textarea><br><br>
76
+
77
+ <button type="submit">Send</button>
78
+ </div>
79
+ </form>
80
+ </body>
81
+ </html>
package/task2.js ADDED
@@ -0,0 +1,43 @@
1
+ const express = require('express');
2
+ const nodemailer = require('nodemailer');
3
+
4
+
5
+ const app = express();
6
+ app.use(express.urlencoded({ extended: true }));
7
+ app.use(express.static('public'));
8
+
9
+ app.get('/', (req, res) => {
10
+ res.sendFile(__dirname + '/task2.html');
11
+ });
12
+
13
+ app.post('/send', (req, res) => {
14
+ const transporter = nodemailer.createTransport({
15
+ host: "smtp.mail.ru",
16
+ port: 465,
17
+ secure: true,
18
+ auth: {
19
+ user: 'andrei_sml@bk.ru',
20
+ // пароль нужно генерить в почте отдельно для сторонних приложений
21
+ pass: '9QshLJ8vfATV5ZeAj8Na'
22
+ }
23
+ });
24
+
25
+ const mailOptions = {
26
+ from: req.body.from,
27
+ to: req.body.to,
28
+ subject: req.body.subject,
29
+ html: req.body.message
30
+ };
31
+
32
+ transporter.sendMail(mailOptions, (error, info) => {
33
+ if (error) {
34
+ console.log(error);
35
+ res.send('Error: Something went wrong.');
36
+ } else {
37
+ console.log('Email sent: ' + info.response);
38
+ res.send('Email sent successfully!');
39
+ }
40
+ });
41
+ }).listen(3000, () => {
42
+ console.log('Server started on port http://localhost:3000');
43
+ });
package/task3.js ADDED
@@ -0,0 +1,7 @@
1
+ const m0603 = require('./m0603');
2
+
3
+ const fromEmail = 'andrei_sml@bk.ru';
4
+ const toEmail = 'andrei.uiu.uiu@gmail.com';
5
+ const password = '9QshLJ8vfATV5ZeAj8Na';
6
+
7
+ m0603.send(fromEmail, password, toEmail, 'Hello from m0603 module!');
package/task4.js ADDED
@@ -0,0 +1,17 @@
1
+ // 1. Регаемся на http://npmjs.com
2
+ // 2. После создания модуля пишем 'npm init' и заполняем данные о пакете
3
+ // 3. Пишем 'npm login <nickname>' и входим в учетку
4
+ // 4. Пишем 'npm publish' и вуаля, пакет в npm
5
+ // 5. npm install
6
+ // 6. npm uninstall
7
+ // 7. To install the m0603 package to the global repository, you can run the npm install -g
8
+ // command in the terminal from the package's root directory. This will install the package globally
9
+ // and make it available for use in any application.
10
+
11
+ const m0603 = require('m0603_adam');
12
+
13
+ const fromEmail = 'andrei_sml@bk.ru';
14
+ const toEmail = 'andrei.uiu.uiu@gmail.com';
15
+ const password = '9QshLJ8vfATV5ZeAj8Na';
16
+
17
+ m0603.send(fromEmail, password, toEmail, 'Hello!');