brichkovskim0603 1.0.1

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.
package/06-02.js ADDED
@@ -0,0 +1,41 @@
1
+ const express = require('express');
2
+ const port = 5000;
3
+ const nodemailer = require('nodemailer');
4
+
5
+
6
+ const app = express();//
7
+
8
+ app.use(express.urlencoded({ extended: true }));//
9
+ app.use(express.static('public'));//
10
+
11
+ app.get('/', (req, res) => {
12
+ res.sendFile(__dirname + '/index.html');
13
+ });
14
+
15
+ app.post('/send',(req,res)=>{
16
+ const transporter = nodemailer.createTransport({
17
+ host: "smtp.mail.ru",
18
+ port: 465,
19
+ secure: true,
20
+ auth:{
21
+ user:"andrei_sml@bk.ru",
22
+ pass:"9QshLJ8vfATV5ZeAj8Na"
23
+ }
24
+ })
25
+
26
+ const mailOptions = {
27
+ from: req.body.from,
28
+ to: req.body.to,
29
+ subject: req.body.subject,
30
+ html: req.body.message
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(port, () => { console.log('Server started on port http://localhost:5000');})
package/06-03.js ADDED
@@ -0,0 +1,22 @@
1
+ const port = 5000;
2
+ const express = require('express');
3
+ const m0603 = require('./m0603');
4
+
5
+ const app = express();
6
+
7
+ app.use(express.urlencoded({ extended: true }));
8
+ app.use(express.static('public'));
9
+
10
+ app.get('/', (req, res) => {
11
+ const fromEmail = 'andrei_sml@bk.ru';
12
+ const toEmail = 'priviknikapp@gmail.com';
13
+ const password = '9QshLJ8vfATV5ZeAj8Na';
14
+ const message = "Привет"
15
+
16
+ m0603.send(fromEmail, password, toEmail, message);
17
+
18
+ res.send("ok");
19
+ });
20
+
21
+ app.listen(3001,
22
+ () => { console.log('Server started on port http://localhost:3001');});
package/index.html ADDED
@@ -0,0 +1,21 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head><title>Отправка сообщения</title></head>
4
+ <bode>
5
+ <form method="post" action="/send">
6
+ <label for="from">From:</label>
7
+ <input type="email" id="from" name="from" required><br><br>
8
+
9
+ <label for="to">To:</label>
10
+ <input type="email" id="to" name="to" required><br><br>
11
+
12
+ <label for="subject">Subject:</label>
13
+ <input type="text" id="subject" name="subject" required><br><br>
14
+
15
+ <label for="message">Message:</label><br>
16
+ <textarea id="message" name="message" rows="10" cols="30" required></textarea><br><br>
17
+
18
+ <button type="submit">Send</button>
19
+ </form>
20
+ </bode>
21
+ </html>
package/m0603.js ADDED
@@ -0,0 +1,28 @@
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
+ let mailOptions = {
14
+ from: from,
15
+ to: to,
16
+ subject: 'Message from m0603 module',
17
+ text: message
18
+ };
19
+
20
+ transporter.sendMail(mailOptions, (error, info) => {
21
+ if (error) {
22
+ console.log(error);
23
+ } else {
24
+ console.log('Message sent: %s', info.messageId);
25
+ }
26
+ });
27
+ }
28
+ module.exports = {send};
package/package.json ADDED
@@ -0,0 +1,16 @@
1
+ {
2
+ "name": "brichkovskim0603",
3
+ "version": "1.0.1",
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": "brich",
11
+ "license": "ISC",
12
+ "dependencies": {
13
+ "express": "^4.18.2",
14
+ "nodemailer": "^6.9.3"
15
+ }
16
+ }