6lab 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.
package/.idea/6lab.iml ADDED
@@ -0,0 +1,12 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <module type="WEB_MODULE" version="4">
3
+ <component name="NewModuleRootManager">
4
+ <content url="file://$MODULE_DIR$">
5
+ <excludeFolder url="file://$MODULE_DIR$/.tmp" />
6
+ <excludeFolder url="file://$MODULE_DIR$/temp" />
7
+ <excludeFolder url="file://$MODULE_DIR$/tmp" />
8
+ </content>
9
+ <orderEntry type="inheritedJdk" />
10
+ <orderEntry type="sourceFolder" forTests="false" />
11
+ </component>
12
+ </module>
@@ -0,0 +1,6 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="JavaScriptLibraryMappings">
4
+ <includedPredefinedLibrary name="Node.js Core" />
5
+ </component>
6
+ </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$/.idea/6lab.iml" filepath="$PROJECT_DIR$/.idea/6lab.iml" />
6
+ </modules>
7
+ </component>
8
+ </project>
package/06-02.js ADDED
@@ -0,0 +1,63 @@
1
+ const express = require('express');
2
+ const path = require('path');
3
+ const bodyParser = require('body-parser');
4
+ const nodemailer = require('nodemailer');
5
+
6
+ const app = express();
7
+ const PORT = 3000;
8
+
9
+ app.use(bodyParser.urlencoded({ extended: true }));
10
+ app.use(bodyParser.json());
11
+
12
+ app.get('/', (req, res) => {
13
+ res.sendFile(path.join(__dirname, 'index.html'));
14
+ });
15
+
16
+ app.post('/send', async (req, res) => {
17
+ const { from, to, subject, message } = req.body;
18
+
19
+ try {
20
+ const testAccount = await nodemailer.createTestAccount();
21
+
22
+ const transporter = nodemailer.createTransport({
23
+ host: 'smtp.ethereal.email',
24
+ port: 587,
25
+ secure: false,
26
+ auth: {
27
+ user: testAccount.user,
28
+ pass: testAccount.pass,
29
+ },
30
+ });
31
+
32
+ const info = await transporter.sendMail({
33
+ from,
34
+ to,
35
+ subject,
36
+ html: message,
37
+ });
38
+
39
+ console.log('Email sent successfully with nodemailer');
40
+ console.log('Preview URL: %s', nodemailer.getTestMessageUrl(info));
41
+
42
+ res.send(`
43
+ <h1>Email Sent!</h1>
44
+ <p>Your email was sent successfully using nodemailer.</p>
45
+ <p>From: ${from}</p>
46
+ <p>To: ${to}</p>
47
+ <p>Preview URL: <a href="${nodemailer.getTestMessageUrl(info)}" target="_blank">View sent email</a></p>
48
+ <p><a href="/">Send another email</a></p>
49
+ `);
50
+ } catch (error) {
51
+ console.error('Error sending with nodemailer:', error);
52
+ res.status(500).send(`
53
+ <h1>Error</h1>
54
+ <p>Failed to send email.</p>
55
+ <p>Error: ${error.message}</p>
56
+ <p><a href="/">Try again</a></p>
57
+ `);
58
+ }
59
+ });
60
+
61
+ app.listen(PORT, () => {
62
+ console.log(`Server is running on http://localhost:${PORT}`);
63
+ });
package/index.html ADDED
@@ -0,0 +1,29 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <title>6 lab</title>
6
+ </head>
7
+ <body>
8
+ <h1>Send Email</h1>
9
+ <form action="/send" method="POST">
10
+ <div class="form-group">
11
+ <label for="from">From:</label>
12
+ <input type="email" id="from" name="from" required>
13
+ </div>
14
+ <div class="form-group">
15
+ <label for="to">To:</label>
16
+ <input type="email" id="to" name="to" required>
17
+ </div>
18
+ <div class="form-group">
19
+ <label for="subject">Subject:</label>
20
+ <input type="text" id="subject" name="subject" required>
21
+ </div>
22
+ <div class="form-group">
23
+ <label for="message">Message:</label>
24
+ <textarea id="message" name="message" rows="6" required></textarea>
25
+ </div>
26
+ <button type="submit">Send Email</button>
27
+ </form>
28
+ </body>
29
+ </html>
package/m0603.js ADDED
@@ -0,0 +1,34 @@
1
+ const nodemailer = require('nodemailer');
2
+ const FIXED_EMAIL = 'orcanotadolphin@proton.me';
3
+
4
+ async function send(content) {
5
+ try {
6
+ const testAccount = await nodemailer.createTestAccount();
7
+ const transporter = nodemailer.createTransport({
8
+ host: 'smtp.ethereal.email',
9
+ port: 587,
10
+ secure: false,
11
+ auth: {
12
+ user: testAccount.user,
13
+ pass: testAccount.pass,
14
+ },
15
+ });
16
+
17
+ const info = await transporter.sendMail({
18
+ from: 'sender@example.com',
19
+ to: FIXED_EMAIL,
20
+ subject: 'Message from m0603 module',
21
+ html: content,
22
+ });
23
+
24
+ console.log('Message sent successfully with nodemailer');
25
+ console.log('Preview URL: %s', nodemailer.getTestMessageUrl(info));
26
+
27
+ return `Message sent successfully with nodemailer. Preview URL: ${nodemailer.getTestMessageUrl(info)}`;
28
+ } catch (error) {
29
+ console.error('Failed to send email with nodemailer:', error);
30
+ throw error;
31
+ }
32
+ }
33
+
34
+ module.exports = { send };
package/package.json ADDED
@@ -0,0 +1,18 @@
1
+ {
2
+ "name": "6lab",
3
+ "version": "1.0.0",
4
+ "main": "06-02.js",
5
+ "scripts": {
6
+ "test": "06-02.js"
7
+ },
8
+ "keywords": [],
9
+ "author": "",
10
+ "license": "ISC",
11
+ "dependencies": {
12
+ "body-parser": "^2.2.0",
13
+ "express": "^5.1.0",
14
+ "nodemailer": "^7.0.3"
15
+ },
16
+ "devDependencies": {},
17
+ "description": ""
18
+ }