mailcub 2.0.9 → 2.0.10
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 +151 -43
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,71 +1,179 @@
|
|
|
1
|
-
# Mailcub
|
|
2
|
-
Version: 2.0.9
|
|
1
|
+
# Mailcub — Send email from Node.js with your domain
|
|
3
2
|
|
|
4
|
-
|
|
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:
|
|
3
|
+
**Mailcub** is a Node.js npm package to send HTML or plain-text emails and attachments using your registered domain. Simple API, secret-key auth, ideal for transactional email and newsletters.
|
|
6
4
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
[](https://www.npmjs.com/package/mailcub)
|
|
6
|
+
[](https://www.npmjs.com/package/mailcub)
|
|
7
|
+
[](https://www.npmjs.com/package/mailcub)
|
|
8
|
+
|
|
9
|
+
---
|
|
10
10
|
|
|
11
11
|
## Installation
|
|
12
|
-
To install the "mailcub" package, use npm:
|
|
13
12
|
|
|
14
13
|
```bash
|
|
15
|
-
|
|
16
14
|
npm install mailcub
|
|
17
|
-
|
|
18
15
|
```
|
|
19
16
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
## Quick example (30-second demo)
|
|
23
20
|
|
|
24
21
|
```javascript
|
|
25
22
|
const mailcub = require('mailcub');
|
|
23
|
+
|
|
24
|
+
const emailBody = {
|
|
25
|
+
email_from: 'hello@yourdomain.com',
|
|
26
|
+
receiver: 'user@example.com',
|
|
27
|
+
subject: 'Welcome',
|
|
28
|
+
html: '<h1>Hello!</h1><p>Thanks for signing up.</p>'
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
mailcub.sendMail(emailBody, 'your-secret-key')
|
|
32
|
+
.then(() => console.log('Email sent'))
|
|
33
|
+
.catch(err => console.error('Error:', err));
|
|
26
34
|
```
|
|
27
35
|
|
|
28
|
-
|
|
29
|
-
|
|
36
|
+
Get your secret key at [client.mailcub.com](https://client.mailcub.com).
|
|
37
|
+
|
|
38
|
+
---
|
|
39
|
+
|
|
40
|
+
## Full API & options
|
|
41
|
+
|
|
42
|
+
### `sendMail(body, key)`
|
|
30
43
|
|
|
31
|
-
|
|
32
|
-
- key (String): The secret key for authentication.
|
|
44
|
+
Sends an email. Returns a Promise.
|
|
33
45
|
|
|
46
|
+
| Parameter | Type | Description |
|
|
47
|
+
|-----------|------|-------------|
|
|
48
|
+
| `body` | Object | Email payload (see below). |
|
|
49
|
+
| `key` | String | Secret key for authentication. From [client.mailcub.com](https://client.mailcub.com). |
|
|
50
|
+
|
|
51
|
+
### `body` object
|
|
52
|
+
|
|
53
|
+
| Field | Type | Required | Description |
|
|
54
|
+
|-------|------|----------|-------------|
|
|
55
|
+
| `email_from` | string | Yes | Sender email (use an address on your registered domain). |
|
|
56
|
+
| `receiver` | string | Yes | Recipient email address. |
|
|
57
|
+
| `subject` | string | Yes | Email subject line. |
|
|
58
|
+
| `html` | string | No* | HTML body of the email. |
|
|
59
|
+
| `text` | string | No* | Plain-text body of the email. Use `html` or `text` (or both). |
|
|
60
|
+
| `attachment` | File or File[] | No | Single file or array of files (file objects only, not paths). |
|
|
61
|
+
|
|
62
|
+
*At least one of `html` or `text` is required.
|
|
63
|
+
|
|
64
|
+
### Examples
|
|
65
|
+
|
|
66
|
+
**Plain text only**
|
|
34
67
|
|
|
35
68
|
```javascript
|
|
36
|
-
|
|
37
|
-
email_from: '
|
|
69
|
+
mailcub.sendMail({
|
|
70
|
+
email_from: 'noreply@yourdomain.com',
|
|
71
|
+
receiver: 'customer@example.com',
|
|
72
|
+
subject: 'Order confirmation',
|
|
73
|
+
text: 'Thank you for your order. Order #1234 has been received.'
|
|
74
|
+
}, process.env.MAILCUB_SECRET_KEY);
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
**HTML only**
|
|
78
|
+
|
|
79
|
+
```javascript
|
|
80
|
+
mailcub.sendMail({
|
|
81
|
+
email_from: 'noreply@yourdomain.com',
|
|
82
|
+
receiver: 'customer@example.com',
|
|
83
|
+
subject: 'Order confirmation',
|
|
84
|
+
html: '<h1>Order #1234</h1><p>Thank you for your order.</p>'
|
|
85
|
+
}, process.env.MAILCUB_SECRET_KEY);
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
**With a single attachment**
|
|
89
|
+
|
|
90
|
+
```javascript
|
|
91
|
+
// attachment = file from request, Postman, etc.
|
|
92
|
+
mailcub.sendMail({
|
|
93
|
+
email_from: 'billing@yourdomain.com',
|
|
94
|
+
receiver: 'client@example.com',
|
|
95
|
+
subject: 'Your invoice',
|
|
96
|
+
html: '<p>Please find your invoice attached.</p>',
|
|
97
|
+
attachment
|
|
98
|
+
}, process.env.MAILCUB_SECRET_KEY);
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
**With multiple attachments**
|
|
102
|
+
|
|
103
|
+
```javascript
|
|
104
|
+
// attachment = array of files (e.g. from request, Postman, etc.)
|
|
105
|
+
mailcub.sendMail({
|
|
106
|
+
email_from: 'team@yourdomain.com',
|
|
38
107
|
receiver: 'user@example.com',
|
|
39
|
-
subject: '
|
|
40
|
-
html: '<
|
|
41
|
-
attachment:
|
|
42
|
-
};
|
|
108
|
+
subject: 'Your documents',
|
|
109
|
+
html: '<p>Attached are the requested files.</p>',
|
|
110
|
+
attachment: [file1, file2]
|
|
111
|
+
}, process.env.MAILCUB_SECRET_KEY);
|
|
112
|
+
```
|
|
43
113
|
|
|
44
|
-
|
|
114
|
+
**Using async/await**
|
|
115
|
+
|
|
116
|
+
```javascript
|
|
117
|
+
const mailcub = require('mailcub');
|
|
45
118
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
119
|
+
async function sendWelcomeEmail(to) {
|
|
120
|
+
try {
|
|
121
|
+
await mailcub.sendMail({
|
|
122
|
+
email_from: 'hello@yourdomain.com',
|
|
123
|
+
receiver: to,
|
|
124
|
+
subject: 'Welcome',
|
|
125
|
+
html: '<h1>Welcome!</h1>'
|
|
126
|
+
}, process.env.MAILCUB_SECRET_KEY);
|
|
127
|
+
return true;
|
|
128
|
+
} catch (err) {
|
|
129
|
+
console.error(err);
|
|
130
|
+
return false;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
53
133
|
```
|
|
54
134
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
135
|
+
---
|
|
136
|
+
|
|
137
|
+
## Why choose Mailcub?
|
|
138
|
+
|
|
139
|
+
- **Simple API** — One function, clear parameters; no SMTP or server config.
|
|
140
|
+
- **Your domain** — Send from your own domain for a professional, branded look.
|
|
141
|
+
- **HTML or plain text** — Send rich HTML or simple plain-text emails (or both).
|
|
142
|
+
- **Attachments** — Single or multiple file attachments.
|
|
143
|
+
- **Secret-key auth** — Secure authentication; keep your key in env vars.
|
|
144
|
+
- **Lightweight** — Minimal dependencies; fits into existing Node.js apps.
|
|
145
|
+
- **Transactional & newsletters** — Suited for both one-off emails and bulk sending.
|
|
146
|
+
|
|
147
|
+
---
|
|
148
|
+
|
|
149
|
+
## Troubleshooting & FAQ
|
|
150
|
+
|
|
151
|
+
**Where do I get the secret key?**
|
|
152
|
+
Sign up and get your key at [client.mailcub.com](https://client.mailcub.com).
|
|
153
|
+
|
|
154
|
+
**"Error sending email" or failed requests**
|
|
155
|
+
- Ensure `email_from` uses a domain you’ve registered in Mailcub.
|
|
156
|
+
- Check that your secret key is correct and not expired.
|
|
157
|
+
- Verify `receiver` and `subject` are non-empty; include at least one of `html` or `text`.
|
|
158
|
+
|
|
159
|
+
**Attachments not sending**
|
|
160
|
+
- `attachment` must be file(s) (e.g. from request, Postman, or your app), not path strings.
|
|
161
|
+
- For multiple files, pass an array: `attachment: [file1, file2]`.
|
|
162
|
+
|
|
163
|
+
**Need help?**
|
|
164
|
+
Contact **support@mailcub.com** or open an issue: [GitHub Issues](https://github.com/devflips/mailcub/issues).
|
|
165
|
+
|
|
166
|
+
---
|
|
167
|
+
|
|
168
|
+
## Contributing & Code of Conduct
|
|
62
169
|
|
|
63
|
-
|
|
170
|
+
Contributions are welcome. Please open an issue or pull request on [GitHub](https://github.com/devflips/mailcub). Be respectful and constructive; we expect a courteous, inclusive environment for everyone.
|
|
64
171
|
|
|
65
|
-
|
|
66
|
-
If you encounter any issues or have questions, please contact our support team at support@mailcub.com.
|
|
172
|
+
---
|
|
67
173
|
|
|
68
|
-
## License
|
|
69
|
-
This package is distributed under the MIT License. See the LICENSE file for details.
|
|
70
174
|
|
|
175
|
+
## License & Author
|
|
71
176
|
|
|
177
|
+
- **License:** [ISC](https://opensource.org/licenses/ISC)
|
|
178
|
+
- **Author:** [Devflips](https://github.com/devflips)
|
|
179
|
+
- **Package:** [npm — mailcub](https://www.npmjs.com/package/mailcub) · [GitHub — mailcub](https://github.com/devflips/mailcub)
|
package/package.json
CHANGED