@upyo/smtp 0.1.0-dev.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 +178 -0
- package/dist/index.cjs +665 -0
- package/dist/index.d.cts +355 -0
- package/dist/index.d.ts +355 -0
- package/dist/index.js +641 -0
- package/package.json +74 -0
package/README.md
ADDED
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
<!-- deno-fmt-ignore-file -->
|
|
2
|
+
|
|
3
|
+
@upyo/smtp
|
|
4
|
+
==========
|
|
5
|
+
|
|
6
|
+
SMTP transport implementation for the Upyo email library.
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
Features
|
|
10
|
+
--------
|
|
11
|
+
|
|
12
|
+
- Full SMTP protocol implementation
|
|
13
|
+
- TLS/SSL support
|
|
14
|
+
- Connection pooling
|
|
15
|
+
- Multiple authentication methods
|
|
16
|
+
- HTML and plain text email support
|
|
17
|
+
- File attachments (regular and inline)
|
|
18
|
+
- Multiple recipients (To, CC, BCC)
|
|
19
|
+
- Custom headers
|
|
20
|
+
- Priority levels
|
|
21
|
+
- Comprehensive testing utilities
|
|
22
|
+
- TypeScript support
|
|
23
|
+
- Cross-runtime compatibility (Node.js, Bun, Deno)
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
TODO
|
|
27
|
+
----
|
|
28
|
+
|
|
29
|
+
- [ ] STARTTLS support (currently only supports direct TLS)
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
Installation
|
|
33
|
+
------------
|
|
34
|
+
|
|
35
|
+
~~~~ sh
|
|
36
|
+
npm add @upyo/core @upyo/smtp
|
|
37
|
+
pnpm add @upyo/core @upyo/smtp
|
|
38
|
+
yarn add @upyo/core @upyo/smtp
|
|
39
|
+
deno add --jsr @upyo/core @upyo/smtp
|
|
40
|
+
bun add @upyo/core @upyo/smtp
|
|
41
|
+
~~~~
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
Usage
|
|
45
|
+
-----
|
|
46
|
+
|
|
47
|
+
### Basic Email Sending
|
|
48
|
+
|
|
49
|
+
~~~~ typescript
|
|
50
|
+
import { SmtpTransport } from "@upyo/smtp";
|
|
51
|
+
import { type Message } from "@upyo/core";
|
|
52
|
+
|
|
53
|
+
const transport = new SmtpTransport({
|
|
54
|
+
host: "smtp.example.com",
|
|
55
|
+
port: 587,
|
|
56
|
+
secure: false,
|
|
57
|
+
auth: {
|
|
58
|
+
user: "username",
|
|
59
|
+
pass: "password",
|
|
60
|
+
},
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
const message: Message = {
|
|
64
|
+
sender: { name: "John Doe", address: "john@example.com" },
|
|
65
|
+
recipients: [{ name: "Jane Doe", address: "jane@example.com" }],
|
|
66
|
+
ccRecipients: [],
|
|
67
|
+
bccRecipients: [],
|
|
68
|
+
replyRecipients: [],
|
|
69
|
+
subject: "Hello from Upyo!",
|
|
70
|
+
content: { text: "This is a test email." },
|
|
71
|
+
attachments: [],
|
|
72
|
+
priority: "normal",
|
|
73
|
+
tags: [],
|
|
74
|
+
headers: new Headers(),
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
const receipt = await transport.send(message);
|
|
78
|
+
console.log("Email sent:", receipt.successful);
|
|
79
|
+
~~~~
|
|
80
|
+
|
|
81
|
+
### HTML Email with Attachments
|
|
82
|
+
|
|
83
|
+
~~~~ typescript
|
|
84
|
+
const message: Message = {
|
|
85
|
+
sender: { address: "sender@example.com" },
|
|
86
|
+
recipients: [{ address: "recipient@example.com" }],
|
|
87
|
+
ccRecipients: [],
|
|
88
|
+
bccRecipients: [],
|
|
89
|
+
replyRecipients: [],
|
|
90
|
+
subject: "HTML Email with Attachment",
|
|
91
|
+
content: {
|
|
92
|
+
html: "<h1>Hello!</h1><p>This is an <strong>HTML</strong> email.</p>",
|
|
93
|
+
text: "Hello!\nThis is an HTML email.",
|
|
94
|
+
},
|
|
95
|
+
attachments: [
|
|
96
|
+
{
|
|
97
|
+
filename: "document.pdf",
|
|
98
|
+
content: new Uint8Array(pdfBytes),
|
|
99
|
+
contentType: "application/pdf",
|
|
100
|
+
contentId: "doc1",
|
|
101
|
+
inline: false,
|
|
102
|
+
},
|
|
103
|
+
],
|
|
104
|
+
priority: "high",
|
|
105
|
+
tags: ["newsletter"],
|
|
106
|
+
headers: new Headers([["X-Campaign-ID", "12345"]]),
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
const receipt = await transport.send(message);
|
|
110
|
+
~~~~
|
|
111
|
+
|
|
112
|
+
### Sending Multiple Emails
|
|
113
|
+
|
|
114
|
+
~~~~ typescript
|
|
115
|
+
const messages = [message1, message2, message3];
|
|
116
|
+
|
|
117
|
+
for await (const receipt of transport.sendMany(messages)) {
|
|
118
|
+
console.log(`Email ${receipt.messageId}: ${receipt.successful ? "sent" : "failed"}`);
|
|
119
|
+
}
|
|
120
|
+
~~~~
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
Configuration options
|
|
124
|
+
---------------------
|
|
125
|
+
|
|
126
|
+
### `SmtpConfig`
|
|
127
|
+
|
|
128
|
+
| Option | Type | Default | Description |
|
|
129
|
+
|---------------------|------------------|---------------|----------------------------------|
|
|
130
|
+
| `host` | `string` | | SMTP server hostname |
|
|
131
|
+
| `port` | `number` | `587` | SMTP server port |
|
|
132
|
+
| `secure` | `boolean` | `true` | Use TLS/SSL connection |
|
|
133
|
+
| `auth` | `SmtpAuth` | | Authentication configuration |
|
|
134
|
+
| `tls` | `SmtpTlsOptions` | | TLS configuration |
|
|
135
|
+
| `connectionTimeout` | `number` | `60000` | Connection timeout (ms) |
|
|
136
|
+
| `socketTimeout` | `number` | `60000` | Socket timeout (ms) |
|
|
137
|
+
| `localName` | `string` | `"localhost"` | Local hostname for `HELO`/`EHLO` |
|
|
138
|
+
| `pool` | `boolean` | `true` | Enable connection pooling |
|
|
139
|
+
| `poolSize` | `number` | `5` | Maximum pool connections |
|
|
140
|
+
|
|
141
|
+
### `SmtpAuth`
|
|
142
|
+
|
|
143
|
+
| Option | Type | Default | Description |
|
|
144
|
+
|----------|------------------------------------|-----------|-------------|
|
|
145
|
+
| `user` | `string` | | Username |
|
|
146
|
+
| `pass` | `string` | | Password |
|
|
147
|
+
| `method` | `"plain" \| "login" \| "cram-md5"` | `"plain"` | Auth method |
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
Testing
|
|
151
|
+
-------
|
|
152
|
+
|
|
153
|
+
### Mock SMTP Server
|
|
154
|
+
|
|
155
|
+
For unit testing, use the included mock SMTP server:
|
|
156
|
+
|
|
157
|
+
~~~~ typescript
|
|
158
|
+
import { MockSmtpServer, SmtpTransport } from "@upyo/smtp";
|
|
159
|
+
|
|
160
|
+
const server = new MockSmtpServer();
|
|
161
|
+
const port = await server.start();
|
|
162
|
+
|
|
163
|
+
const transport = new SmtpTransport({
|
|
164
|
+
host: "localhost",
|
|
165
|
+
port,
|
|
166
|
+
secure: false,
|
|
167
|
+
auth: { user: "test", pass: "test" },
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
// Send test email
|
|
171
|
+
await transport.send(message);
|
|
172
|
+
|
|
173
|
+
// Check received messages
|
|
174
|
+
const received = server.getReceivedMessages();
|
|
175
|
+
console.log(received[0].data); // Raw email content
|
|
176
|
+
|
|
177
|
+
await server.stop();
|
|
178
|
+
~~~~
|