mailcub 2.0.5

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/README.md ADDED
@@ -0,0 +1,71 @@
1
+ # Mailcub Package Documentation
2
+ Version: 2.0.4
3
+
4
+ ## Introduction
5
+ Mailcub is an npm package that enables you to send emails using a simple and straightforward interface. It provides a function to send emails with the following features:
6
+
7
+ ## Sending HTML emails.
8
+ Attaching files to emails.
9
+ Sending emails with a secret key for authentication.
10
+
11
+ ## Installation
12
+ To install the "mailcub" package, use npm:
13
+
14
+ ```bash
15
+
16
+ npm install mailcub
17
+
18
+ ```
19
+
20
+ ## Usage
21
+ ### Import the Package
22
+ You can import the "mailcub" package in your Node.js application as follows:
23
+
24
+ ```javascript
25
+ const mailcub = require('mailcub');
26
+ ```
27
+
28
+ ### Sending an Email
29
+ To send an email, use the sendMail function with the following parameters:
30
+
31
+ - body (Object): An object containing the email details.
32
+ - key (String): The secret key for authentication.
33
+
34
+
35
+ ```javascript
36
+ const emailBody = {
37
+ email_from: 'user@yourdomain.com',
38
+ receiver: 'user@example.com',
39
+ subject: 'Subject',
40
+ html: '<h1>Hello</h1>',
41
+ attachment: 'attachment_path'
42
+ };
43
+
44
+ const secretKey = 'your-secret-key';
45
+
46
+ mailcub.sendMail(emailBody, secretKey)
47
+ .then(() => {
48
+ console.log('Email sent successfully');
49
+ })
50
+ .catch((error) => {
51
+ console.error('Error sending email:', error);
52
+ });
53
+ ```
54
+
55
+ ## Parameters
56
+ - emailBody (Object):
57
+ - email_from (String): The sender's email address.
58
+ - receiver (String): The recipient's email address.
59
+ - subject (String): The email subject.
60
+ - html (String): The HTML content of the email.
61
+ - attachment (String or Array): The file path of a single attachment, or an array of file paths for multiple attachments — e.g., ['path/to/file1', 'path/to/file2', 'path/to/file3'].
62
+
63
+ - secretKey (String): The secret key for authentication. You can obtain this key from console.mailcub.com.
64
+
65
+ ## Support and Issues
66
+ If you encounter any issues or have questions, please contact our support team at support@mailcub.com.
67
+
68
+ ## License
69
+ This package is distributed under the MIT License. See the LICENSE file for details.
70
+
71
+
package/index.js ADDED
@@ -0,0 +1,39 @@
1
+ const invokeApi = require("./invoke_api");
2
+
3
+ const sendMail = async (body, key) => {
4
+ try {
5
+ const requestObj = {
6
+ path: "https://api.mail.mailcub.com/api/send_email",
7
+ method: "POST",
8
+ headers: {
9
+ "Content-Type": "application/json",
10
+ "x-sh-key": key,
11
+ },
12
+ postData: body,
13
+ };
14
+
15
+ const result = await invokeApi(requestObj);
16
+
17
+ if (result.code !== 200) {
18
+ const error = new Error(result.message || "Unknown error from Mailcub API");
19
+ error.code = result.code;
20
+ throw error;
21
+ }
22
+
23
+ return {
24
+ code: result.code,
25
+ message: result.message,
26
+ };
27
+
28
+ } catch (err) {
29
+ throw {
30
+ code: err.code || 500,
31
+ message: err.message || "An unexpected error occurred while sending email."
32
+ };
33
+ }
34
+ };
35
+
36
+ module.exports = {
37
+ sendMail,
38
+ };
39
+
package/invoke_api.js ADDED
@@ -0,0 +1,48 @@
1
+ const axios = require("axios");
2
+ axios.defaults.headers.post["Content-Type"] = "application/json";
3
+
4
+ async function invokeApi({
5
+ path,
6
+ method = "GET",
7
+ headers = {},
8
+ queryParams = {},
9
+ postData = {},
10
+ }) {
11
+ const reqObj = {
12
+ method,
13
+ url: path,
14
+ headers: {...headers},
15
+ params: queryParams,
16
+ data: postData,
17
+ };
18
+
19
+ let results;
20
+
21
+ try {
22
+ // console.log("axios requestOBJ ==> ", reqObj);
23
+ results = await axios(reqObj);
24
+ // console.log(results, "API results");
25
+ return results.data;
26
+ } catch (error) {
27
+ // console.error(error);
28
+
29
+ if (error.response && error.response.status === 401) {
30
+ // alert(reqObj.url)
31
+ // localStorage.clear();
32
+ // window.location.reload();
33
+ }
34
+
35
+ const errorMessage =
36
+ error.response?.data?.message ||
37
+ "" ||
38
+ error.response?.statusText ||
39
+ "Something went wrong";
40
+
41
+ return {
42
+ code: error.response?.status || 500,
43
+ message: errorMessage,
44
+ };
45
+ }
46
+ }
47
+
48
+ module.exports = invokeApi;
package/package.json ADDED
@@ -0,0 +1,23 @@
1
+ {
2
+ "name": "mailcub",
3
+ "version": "2.0.5",
4
+ "description": "This package enables users to send emails using their registered domains, providing a professional and branded approach to communication.",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "test": "echo \"Error: no test specified\" && exit 1"
8
+ },
9
+ "dependencies": {
10
+ "axios": "^1.4.0"
11
+ },
12
+ "devDependencies": {},
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "git+ssh://git@github.com:devflips/mailcub.git"
16
+ },
17
+ "author": "Devflips",
18
+ "license": "ISC",
19
+ "bugs": {
20
+ "url": "https://github.com/devflips/mailcub/issues"
21
+ },
22
+ "homepage": "https://github.com/devflips/mailcub#readme"
23
+ }