panoramatrack-helper 1.0.0 → 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/index.js +45 -2
- package/package.json +6 -3
- package/test/index.js +23 -2
package/index.js
CHANGED
@@ -1,8 +1,51 @@
|
|
1
1
|
//index.js
|
2
|
+
const nodemailer = require("nodemailer");
|
2
3
|
|
4
|
+
// Function to send an email
|
5
|
+
const sendEmail = async (mailConfig, Options) => {
|
6
|
+
const response = {};
|
7
|
+
try {
|
8
|
+
// Create a transporter with SMTP configuration
|
9
|
+
const transporter = nodemailer.createTransport({
|
10
|
+
host: mailConfig.host,
|
11
|
+
port: mailConfig.port,
|
12
|
+
secure: mailConfig.secure,
|
13
|
+
auth: {
|
14
|
+
user: mailConfig.user,
|
15
|
+
pass: mailConfig.pass,
|
16
|
+
},
|
17
|
+
});
|
18
|
+
|
19
|
+
// Define email options
|
20
|
+
const mailOptions = {
|
21
|
+
from: Options.from,
|
22
|
+
to: Options.to,
|
23
|
+
subject: Options.subject,
|
24
|
+
html: Options.html,
|
25
|
+
};
|
26
|
+
|
27
|
+
// Send the email
|
28
|
+
// console.log('Email sent:', info.messageId);
|
29
|
+
const info = await transporter.sendMail(mailOptions);
|
30
|
+
response.status_code = 200;
|
31
|
+
response.status = true;
|
32
|
+
response.messageId = info.messageId;
|
33
|
+
return response;
|
34
|
+
} catch (error) {
|
35
|
+
// console.error('Error sending email:', error);
|
36
|
+
response.status_code = 500;
|
37
|
+
response.status = false;
|
38
|
+
response.error = error;
|
39
|
+
return response;
|
40
|
+
}
|
41
|
+
};
|
42
|
+
|
43
|
+
// Function to test the helper
|
3
44
|
function test() {
|
4
45
|
return "Test helper.";
|
5
46
|
}
|
47
|
+
|
6
48
|
module.exports = {
|
7
|
-
|
8
|
-
|
49
|
+
sendEmail,
|
50
|
+
test,
|
51
|
+
};
|
package/package.json
CHANGED
@@ -1,11 +1,14 @@
|
|
1
1
|
{
|
2
2
|
"name": "panoramatrack-helper",
|
3
|
-
"version": "1.0.
|
3
|
+
"version": "1.0.1",
|
4
4
|
"description": "panoramatrack helper",
|
5
5
|
"main": "index.js",
|
6
6
|
"scripts": {
|
7
7
|
"test": "echo \"Error: no test specified\" && exit 1"
|
8
8
|
},
|
9
9
|
"author": "Dolan Chowdhury",
|
10
|
-
"license": "ISC"
|
11
|
-
|
10
|
+
"license": "ISC",
|
11
|
+
"dependencies": {
|
12
|
+
"nodemailer": "^6.9.3"
|
13
|
+
}
|
14
|
+
}
|
package/test/index.js
CHANGED
@@ -1,2 +1,23 @@
|
|
1
|
-
const { test } = require(
|
2
|
-
|
1
|
+
const { test } = require("..");
|
2
|
+
const { sendEmail } = require("..");
|
3
|
+
console.log("Test Email");
|
4
|
+
// Usage example
|
5
|
+
mailConfig = {
|
6
|
+
host: "",
|
7
|
+
port: 2525,
|
8
|
+
secure: false,
|
9
|
+
user: "",
|
10
|
+
pass: "",
|
11
|
+
};
|
12
|
+
// Define email options
|
13
|
+
const mailOptions = {
|
14
|
+
from: "test@mailinator.com",
|
15
|
+
to: "test@mailinator.com",
|
16
|
+
subject: "Test Email",
|
17
|
+
html: "This is a test email.",
|
18
|
+
};
|
19
|
+
// sendEmail(mailConfig,mailOptions)
|
20
|
+
// .then(() => console.log('Email sent successfully.'))
|
21
|
+
// .catch((error) => console.error('Error sending email:', error));
|
22
|
+
|
23
|
+
// console.log(test());
|