@upyo/mailtrap 0.6.0-dev.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/LICENSE +20 -0
- package/README.md +109 -0
- package/dist/index.cjs +656 -0
- package/dist/index.d.cts +323 -0
- package/dist/index.d.ts +323 -0
- package/dist/index.js +630 -0
- package/package.json +65 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright 2025 Hong Minhee
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
6
|
+
this software and associated documentation files (the "Software"), to deal in
|
|
7
|
+
the Software without restriction, including without limitation the rights to
|
|
8
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
9
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
|
10
|
+
subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
17
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
18
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
19
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
20
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
<!-- deno-fmt-ignore-file -->
|
|
2
|
+
|
|
3
|
+
@upyo/mailtrap
|
|
4
|
+
==============
|
|
5
|
+
|
|
6
|
+
[![JSR][JSR badge]][JSR]
|
|
7
|
+
[![npm][npm badge]][npm]
|
|
8
|
+
|
|
9
|
+
[Mailtrap] transport for the [Upyo] email library.
|
|
10
|
+
|
|
11
|
+
[JSR badge]: https://jsr.io/badges/@upyo/mailtrap
|
|
12
|
+
[JSR]: https://jsr.io/@upyo/mailtrap
|
|
13
|
+
[npm badge]: https://img.shields.io/npm/v/@upyo/mailtrap?logo=npm
|
|
14
|
+
[npm]: https://www.npmjs.com/package/@upyo/mailtrap
|
|
15
|
+
[Mailtrap]: https://mailtrap.io/
|
|
16
|
+
[Upyo]: https://upyo.org/
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
Features
|
|
20
|
+
--------
|
|
21
|
+
|
|
22
|
+
- Single and batch email sending via Mailtrap's HTTP API
|
|
23
|
+
- Email API (production) and Email Sandbox (test inbox) support
|
|
24
|
+
- Cross-runtime compatibility (Node.js, Deno, Bun, edge functions)
|
|
25
|
+
- Rich content support: HTML emails, attachments, inline images, and custom
|
|
26
|
+
headers
|
|
27
|
+
- Category, custom variables, and config-level metadata
|
|
28
|
+
- Retry logic with exponential backoff
|
|
29
|
+
- Type-safe configuration with sensible defaults
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
Installation
|
|
33
|
+
------------
|
|
34
|
+
|
|
35
|
+
~~~~ sh
|
|
36
|
+
npm add @upyo/core @upyo/mailtrap
|
|
37
|
+
pnpm add @upyo/core @upyo/mailtrap
|
|
38
|
+
yarn add @upyo/core @upyo/mailtrap
|
|
39
|
+
deno add --jsr @upyo/core @upyo/mailtrap
|
|
40
|
+
bun add @upyo/core @upyo/mailtrap
|
|
41
|
+
~~~~
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
Usage
|
|
45
|
+
-----
|
|
46
|
+
|
|
47
|
+
~~~~ typescript
|
|
48
|
+
import { createMessage } from "@upyo/core";
|
|
49
|
+
import { MailtrapTransport } from "@upyo/mailtrap";
|
|
50
|
+
import process from "node:process";
|
|
51
|
+
|
|
52
|
+
const transport = new MailtrapTransport({
|
|
53
|
+
apiToken: process.env.MAILTRAP_API_TOKEN!,
|
|
54
|
+
sandbox: process.env.MAILTRAP_SANDBOX === "true",
|
|
55
|
+
inboxId: process.env.MAILTRAP_INBOX_ID,
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
const message = createMessage({
|
|
59
|
+
from: "sender@example.com",
|
|
60
|
+
to: "recipient@example.net",
|
|
61
|
+
subject: "Hello from Upyo!",
|
|
62
|
+
content: { text: "This is a test email." },
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
const receipt = await transport.send(message);
|
|
66
|
+
if (receipt.successful) {
|
|
67
|
+
console.log("Message sent with ID:", receipt.messageId);
|
|
68
|
+
} else {
|
|
69
|
+
console.error("Send failed:", receipt.errorMessages.join(", "));
|
|
70
|
+
}
|
|
71
|
+
~~~~
|
|
72
|
+
|
|
73
|
+
### Sending multiple emails
|
|
74
|
+
|
|
75
|
+
~~~~ typescript
|
|
76
|
+
const messages = [message1, message2, message3];
|
|
77
|
+
|
|
78
|
+
for await (const receipt of transport.sendMany(messages)) {
|
|
79
|
+
if (receipt.successful) {
|
|
80
|
+
console.log(`Email sent with ID: ${receipt.messageId}`);
|
|
81
|
+
} else {
|
|
82
|
+
console.error(`Email failed: ${receipt.errorMessages.join(", ")}`);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
~~~~
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
Configuration
|
|
89
|
+
-------------
|
|
90
|
+
|
|
91
|
+
See the [Mailtrap docs] for more information about API tokens and sandboxes.
|
|
92
|
+
|
|
93
|
+
[Mailtrap docs]: https://docs.mailtrap.io/
|
|
94
|
+
|
|
95
|
+
### Available options
|
|
96
|
+
|
|
97
|
+
- `apiToken`: Your Mailtrap API token
|
|
98
|
+
- `sandbox`: Use Email Sandbox instead of Email API (default: `false`)
|
|
99
|
+
- `inboxId`: Sandbox inbox ID (required when `sandbox` is `true`)
|
|
100
|
+
- `sendBaseUrl`: Email API base URL (default: `https://send.api.mailtrap.io`)
|
|
101
|
+
- `sandboxBaseUrl`: Sandbox API base URL (default:
|
|
102
|
+
`https://sandbox.api.mailtrap.io`)
|
|
103
|
+
- `defaultCategory`: Default category when a message has no tags (default:
|
|
104
|
+
`transactional`)
|
|
105
|
+
- `metadata`: Metadata to track with sent messages
|
|
106
|
+
- `userAgent`: User-Agent header (default: `@upyo/mailtrap`)
|
|
107
|
+
- `timeout`: Request timeout in milliseconds (default: `30000`)
|
|
108
|
+
- `retries`: Number of retry attempts (default: `3`)
|
|
109
|
+
- `headers`: Additional HTTP headers
|