@talosjs/mailer 1.1.0 → 1.1.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/README.md +4 -405
- package/package.json +8 -8
package/README.md
CHANGED
|
@@ -1,24 +1,6 @@
|
|
|
1
1
|
# @talosjs/mailer
|
|
2
2
|
|
|
3
|
-
Transactional email service supporting Nodemailer SMTP and Resend API
|
|
4
|
-
|
|
5
|
-

|
|
6
|
-

|
|
7
|
-

|
|
8
|
-
|
|
9
|
-
## Features
|
|
10
|
-
|
|
11
|
-
✅ **Resend API** - Send transactional emails via the Resend service
|
|
12
|
-
|
|
13
|
-
✅ **React Templates** - Build email templates using React components with server-side rendering
|
|
14
|
-
|
|
15
|
-
✅ **Layout System** - Pre-built email layout with header, body, and footer components
|
|
16
|
-
|
|
17
|
-
✅ **Environment Configuration** - Configure sender and API keys via environment variables
|
|
18
|
-
|
|
19
|
-
✅ **Container Integration** - Decorator-based registration with dependency injection
|
|
20
|
-
|
|
21
|
-
✅ **Error Handling** - Comprehensive error handling with custom MailerException
|
|
3
|
+
Transactional email service supporting Nodemailer SMTP and Resend API — send templated emails with attachments and delivery tracking
|
|
22
4
|
|
|
23
5
|
## Installation
|
|
24
6
|
|
|
@@ -26,393 +8,10 @@ Transactional email service supporting Nodemailer SMTP and Resend API -- send te
|
|
|
26
8
|
bun add @talosjs/mailer
|
|
27
9
|
```
|
|
28
10
|
|
|
29
|
-
##
|
|
30
|
-
|
|
31
|
-
### Basic Usage with Resend
|
|
32
|
-
|
|
33
|
-
```typescript
|
|
34
|
-
import { ResendMailer } from '@talosjs/mailer';
|
|
35
|
-
|
|
36
|
-
const mailer = new ResendMailer({
|
|
37
|
-
apiKey: 'your-resend-api-key'
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
await mailer.send({
|
|
41
|
-
to: ['user@example.com'],
|
|
42
|
-
subject: 'Welcome to our platform!',
|
|
43
|
-
content: <WelcomeEmail userName="John" />
|
|
44
|
-
});
|
|
45
|
-
```
|
|
46
|
-
|
|
47
|
-
### Using Nodemailer SMTP
|
|
48
|
-
|
|
49
|
-
```typescript
|
|
50
|
-
import { NodeMailerAdapter } from '@talosjs/mailer';
|
|
51
|
-
|
|
52
|
-
const mailer = new NodeMailerAdapter({
|
|
53
|
-
host: 'smtp.example.com',
|
|
54
|
-
port: 587,
|
|
55
|
-
secure: false,
|
|
56
|
-
auth: {
|
|
57
|
-
user: 'your-username',
|
|
58
|
-
pass: 'your-password'
|
|
59
|
-
}
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
await mailer.send({
|
|
63
|
-
to: ['user@example.com'],
|
|
64
|
-
subject: 'Hello from Nodemailer!',
|
|
65
|
-
content: <SimpleEmail message="Hello World" />
|
|
66
|
-
});
|
|
67
|
-
```
|
|
68
|
-
|
|
69
|
-
### With Environment Variables
|
|
70
|
-
|
|
71
|
-
```typescript
|
|
72
|
-
import { ResendMailer } from '@talosjs/mailer';
|
|
73
|
-
|
|
74
|
-
// Automatically uses MAILER_RESEND_API_KEY environment variable
|
|
75
|
-
const mailer = new ResendMailer();
|
|
76
|
-
|
|
77
|
-
await mailer.send({
|
|
78
|
-
to: ['user@example.com'],
|
|
79
|
-
subject: 'Test Email',
|
|
80
|
-
content: <TestEmail />
|
|
81
|
-
});
|
|
82
|
-
```
|
|
83
|
-
|
|
84
|
-
**Environment Variables:**
|
|
85
|
-
- `MAILER_RESEND_API_KEY` - Resend API key
|
|
86
|
-
- `MAILER_SMTP_HOST` - SMTP server host
|
|
87
|
-
- `MAILER_SMTP_PORT` - SMTP server port
|
|
88
|
-
- `MAILER_SMTP_USER` - SMTP username
|
|
89
|
-
- `MAILER_SMTP_PASS` - SMTP password
|
|
90
|
-
|
|
91
|
-
### Using the Email Layout
|
|
92
|
-
|
|
93
|
-
```typescript
|
|
94
|
-
import { MailerLayout } from '@talosjs/mailer';
|
|
95
|
-
|
|
96
|
-
function WelcomeEmail({ userName }: { userName: string }) {
|
|
97
|
-
return (
|
|
98
|
-
<MailerLayout
|
|
99
|
-
title="Welcome"
|
|
100
|
-
previewText="Welcome to our platform!"
|
|
101
|
-
>
|
|
102
|
-
<h1>Hello, {userName}!</h1>
|
|
103
|
-
<p>Thank you for joining us.</p>
|
|
104
|
-
<a href="https://example.com/dashboard">Get Started</a>
|
|
105
|
-
</MailerLayout>
|
|
106
|
-
);
|
|
107
|
-
}
|
|
108
|
-
```
|
|
109
|
-
|
|
110
|
-
### Custom Sender Information
|
|
111
|
-
|
|
112
|
-
```typescript
|
|
113
|
-
import { ResendMailer } from '@talosjs/mailer';
|
|
114
|
-
|
|
115
|
-
const mailer = new ResendMailer();
|
|
116
|
-
|
|
117
|
-
await mailer.send({
|
|
118
|
-
to: ['user@example.com'],
|
|
119
|
-
subject: 'Important Update',
|
|
120
|
-
content: <UpdateEmail />,
|
|
121
|
-
from: {
|
|
122
|
-
name: 'Support Team',
|
|
123
|
-
address: 'support@example.com'
|
|
124
|
-
}
|
|
125
|
-
});
|
|
126
|
-
```
|
|
127
|
-
|
|
128
|
-
## API Reference
|
|
129
|
-
|
|
130
|
-
### Classes
|
|
131
|
-
|
|
132
|
-
#### `ResendMailer`
|
|
133
|
-
|
|
134
|
-
Email adapter using the Resend API for sending emails.
|
|
135
|
-
|
|
136
|
-
**Constructor:**
|
|
137
|
-
```typescript
|
|
138
|
-
new ResendMailer(options?: { apiKey?: string })
|
|
139
|
-
```
|
|
140
|
-
|
|
141
|
-
**Parameters:**
|
|
142
|
-
- `options.apiKey` - Resend API key (optional if set via environment variable)
|
|
143
|
-
|
|
144
|
-
**Methods:**
|
|
145
|
-
|
|
146
|
-
##### `send(config: SendConfig): Promise<void>`
|
|
147
|
-
|
|
148
|
-
Sends an email using the Resend API.
|
|
149
|
-
|
|
150
|
-
**Parameters:**
|
|
151
|
-
- `config.to` - Array of recipient email addresses
|
|
152
|
-
- `config.subject` - Email subject line
|
|
153
|
-
- `config.content` - React node to render as email body
|
|
154
|
-
- `config.from` - Optional sender information
|
|
155
|
-
|
|
156
|
-
**Example:**
|
|
157
|
-
```typescript
|
|
158
|
-
const mailer = new ResendMailer();
|
|
159
|
-
|
|
160
|
-
await mailer.send({
|
|
161
|
-
to: ['recipient@example.com'],
|
|
162
|
-
subject: 'Welcome!',
|
|
163
|
-
content: <WelcomeEmail />
|
|
164
|
-
});
|
|
165
|
-
```
|
|
166
|
-
|
|
167
|
-
---
|
|
168
|
-
|
|
169
|
-
#### `NodeMailerAdapter`
|
|
170
|
-
|
|
171
|
-
Email adapter using Nodemailer for SMTP-based email sending.
|
|
172
|
-
|
|
173
|
-
**Constructor:**
|
|
174
|
-
```typescript
|
|
175
|
-
new NodeMailerAdapter(options?: NodeMailerOptionsType)
|
|
176
|
-
```
|
|
177
|
-
|
|
178
|
-
**Parameters:**
|
|
179
|
-
- `options.host` - SMTP server hostname
|
|
180
|
-
- `options.port` - SMTP server port
|
|
181
|
-
- `options.secure` - Use TLS (default: false for port 587)
|
|
182
|
-
- `options.auth.user` - SMTP username
|
|
183
|
-
- `options.auth.pass` - SMTP password
|
|
184
|
-
|
|
185
|
-
**Methods:**
|
|
186
|
-
|
|
187
|
-
##### `send(config: SendConfig): Promise<void>`
|
|
188
|
-
|
|
189
|
-
Sends an email using SMTP.
|
|
190
|
-
|
|
191
|
-
**Parameters:**
|
|
192
|
-
Same as `ResendMailer.send()`
|
|
193
|
-
|
|
194
|
-
---
|
|
195
|
-
|
|
196
|
-
#### `MailerLayout`
|
|
197
|
-
|
|
198
|
-
React component providing a pre-styled email layout.
|
|
199
|
-
|
|
200
|
-
**Props:**
|
|
201
|
-
- `title` - Email title (for document head)
|
|
202
|
-
- `previewText` - Preview text shown in email clients
|
|
203
|
-
- `children` - Email content
|
|
204
|
-
|
|
205
|
-
**Example:**
|
|
206
|
-
```typescript
|
|
207
|
-
<MailerLayout
|
|
208
|
-
title="Order Confirmation"
|
|
209
|
-
previewText="Your order has been confirmed"
|
|
210
|
-
>
|
|
211
|
-
<h1>Thank you for your order!</h1>
|
|
212
|
-
<p>Order #12345 has been confirmed.</p>
|
|
213
|
-
</MailerLayout>
|
|
214
|
-
```
|
|
215
|
-
|
|
216
|
-
### Interfaces
|
|
217
|
-
|
|
218
|
-
#### `IMailer`
|
|
219
|
-
|
|
220
|
-
```typescript
|
|
221
|
-
interface IMailer {
|
|
222
|
-
send: (config: {
|
|
223
|
-
to: string[];
|
|
224
|
-
subject: string;
|
|
225
|
-
content: React.ReactNode;
|
|
226
|
-
from?: { name: string; address: string };
|
|
227
|
-
}) => Promise<void>;
|
|
228
|
-
}
|
|
229
|
-
```
|
|
230
|
-
|
|
231
|
-
### Types
|
|
232
|
-
|
|
233
|
-
#### `MailerClassType`
|
|
234
|
-
|
|
235
|
-
```typescript
|
|
236
|
-
type MailerClassType = new (...args: any[]) => IMailer;
|
|
237
|
-
```
|
|
238
|
-
|
|
239
|
-
## Advanced Usage
|
|
240
|
-
|
|
241
|
-
### Integration with Talos App
|
|
242
|
-
|
|
243
|
-
```typescript
|
|
244
|
-
import { App } from '@talosjs/app';
|
|
245
|
-
import { ResendMailer } from '@talosjs/mailer';
|
|
246
|
-
|
|
247
|
-
const app = new App({
|
|
248
|
-
mailer: ResendMailer,
|
|
249
|
-
// ... other config
|
|
250
|
-
});
|
|
251
|
-
|
|
252
|
-
await app.run();
|
|
253
|
-
```
|
|
254
|
-
|
|
255
|
-
### Using in Controllers
|
|
256
|
-
|
|
257
|
-
```typescript
|
|
258
|
-
import { Route } from '@talosjs/routing';
|
|
259
|
-
import type { IController, ContextType } from '@talosjs/controller';
|
|
260
|
-
|
|
261
|
-
@Route.http({
|
|
262
|
-
name: 'api.users.invite',
|
|
263
|
-
path: '/api/users/invite',
|
|
264
|
-
method: 'POST',
|
|
265
|
-
description: 'Send invitation email'
|
|
266
|
-
})
|
|
267
|
-
class InviteUserController implements IController {
|
|
268
|
-
public async index(context: ContextType): Promise<IResponse> {
|
|
269
|
-
const { email, name } = context.payload;
|
|
270
|
-
|
|
271
|
-
await context.mailer?.send({
|
|
272
|
-
to: [email],
|
|
273
|
-
subject: 'You are invited!',
|
|
274
|
-
content: <InvitationEmail recipientName={name} />
|
|
275
|
-
});
|
|
276
|
-
|
|
277
|
-
return context.response.json({ sent: true });
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
```
|
|
281
|
-
|
|
282
|
-
### Container Registration with Decorator
|
|
283
|
-
|
|
284
|
-
```typescript
|
|
285
|
-
import { container } from '@talosjs/container';
|
|
286
|
-
import { ResendMailer, decorator } from '@talosjs/mailer';
|
|
287
|
-
|
|
288
|
-
// Register with container using decorator
|
|
289
|
-
@decorator.mailer()
|
|
290
|
-
class MyMailerService extends ResendMailer {
|
|
291
|
-
// Custom implementation
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
// Resolve from container
|
|
295
|
-
const mailer = container.get(MyMailerService);
|
|
296
|
-
```
|
|
297
|
-
|
|
298
|
-
### Error Handling
|
|
299
|
-
|
|
300
|
-
```typescript
|
|
301
|
-
import { ResendMailer, MailerException } from '@talosjs/mailer';
|
|
302
|
-
|
|
303
|
-
const mailer = new ResendMailer();
|
|
304
|
-
|
|
305
|
-
try {
|
|
306
|
-
await mailer.send({
|
|
307
|
-
to: ['user@example.com'],
|
|
308
|
-
subject: 'Test',
|
|
309
|
-
content: <TestEmail />
|
|
310
|
-
});
|
|
311
|
-
} catch (error) {
|
|
312
|
-
if (error instanceof MailerException) {
|
|
313
|
-
console.error('Mailer Error:', error.message);
|
|
314
|
-
// Handle email-specific error
|
|
315
|
-
}
|
|
316
|
-
}
|
|
317
|
-
```
|
|
318
|
-
|
|
319
|
-
### Building Custom Email Templates
|
|
11
|
+
## Documentation
|
|
320
12
|
|
|
321
|
-
|
|
322
|
-
import { MailerLayout } from '@talosjs/mailer';
|
|
323
|
-
|
|
324
|
-
interface OrderConfirmationProps {
|
|
325
|
-
orderId: string;
|
|
326
|
-
items: Array<{ name: string; price: number }>;
|
|
327
|
-
total: number;
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
function OrderConfirmationEmail({ orderId, items, total }: OrderConfirmationProps) {
|
|
331
|
-
return (
|
|
332
|
-
<MailerLayout
|
|
333
|
-
title="Order Confirmation"
|
|
334
|
-
previewText={`Order #${orderId} confirmed`}
|
|
335
|
-
>
|
|
336
|
-
<div style={{ fontFamily: 'Arial, sans-serif' }}>
|
|
337
|
-
<h1 style={{ color: '#333' }}>Order Confirmed!</h1>
|
|
338
|
-
<p>Order ID: <strong>{orderId}</strong></p>
|
|
339
|
-
|
|
340
|
-
<table style={{ width: '100%', borderCollapse: 'collapse' }}>
|
|
341
|
-
<thead>
|
|
342
|
-
<tr>
|
|
343
|
-
<th style={{ textAlign: 'left', padding: '8px' }}>Item</th>
|
|
344
|
-
<th style={{ textAlign: 'right', padding: '8px' }}>Price</th>
|
|
345
|
-
</tr>
|
|
346
|
-
</thead>
|
|
347
|
-
<tbody>
|
|
348
|
-
{items.map((item, index) => (
|
|
349
|
-
<tr key={index}>
|
|
350
|
-
<td style={{ padding: '8px' }}>{item.name}</td>
|
|
351
|
-
<td style={{ textAlign: 'right', padding: '8px' }}>
|
|
352
|
-
${item.price.toFixed(2)}
|
|
353
|
-
</td>
|
|
354
|
-
</tr>
|
|
355
|
-
))}
|
|
356
|
-
</tbody>
|
|
357
|
-
<tfoot>
|
|
358
|
-
<tr>
|
|
359
|
-
<td style={{ padding: '8px', fontWeight: 'bold' }}>Total</td>
|
|
360
|
-
<td style={{ textAlign: 'right', padding: '8px', fontWeight: 'bold' }}>
|
|
361
|
-
${total.toFixed(2)}
|
|
362
|
-
</td>
|
|
363
|
-
</tr>
|
|
364
|
-
</tfoot>
|
|
365
|
-
</table>
|
|
366
|
-
|
|
367
|
-
<p style={{ marginTop: '20px' }}>
|
|
368
|
-
Thank you for your purchase!
|
|
369
|
-
</p>
|
|
370
|
-
</div>
|
|
371
|
-
</MailerLayout>
|
|
372
|
-
);
|
|
373
|
-
}
|
|
374
|
-
```
|
|
375
|
-
|
|
376
|
-
### Sending to Multiple Recipients
|
|
377
|
-
|
|
378
|
-
```typescript
|
|
379
|
-
import { ResendMailer } from '@talosjs/mailer';
|
|
380
|
-
|
|
381
|
-
const mailer = new ResendMailer();
|
|
382
|
-
|
|
383
|
-
await mailer.send({
|
|
384
|
-
to: [
|
|
385
|
-
'user1@example.com',
|
|
386
|
-
'user2@example.com',
|
|
387
|
-
'user3@example.com'
|
|
388
|
-
],
|
|
389
|
-
subject: 'Team Announcement',
|
|
390
|
-
content: <AnnouncementEmail />
|
|
391
|
-
});
|
|
392
|
-
```
|
|
13
|
+
Read the full documentation at [docs.talosjs.com/components/mailer](https://docs.talosjs.com/components/mailer).
|
|
393
14
|
|
|
394
15
|
## License
|
|
395
16
|
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
## Contributing
|
|
399
|
-
|
|
400
|
-
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
|
|
401
|
-
|
|
402
|
-
### Development Setup
|
|
403
|
-
|
|
404
|
-
1. Clone the repository
|
|
405
|
-
2. Install dependencies: `bun install`
|
|
406
|
-
3. Run tests: `bun run test`
|
|
407
|
-
4. Build the project: `bun run build`
|
|
408
|
-
|
|
409
|
-
### Guidelines
|
|
410
|
-
|
|
411
|
-
- Write tests for new features
|
|
412
|
-
- Follow the existing code style
|
|
413
|
-
- Update documentation for API changes
|
|
414
|
-
- Ensure all tests pass before submitting PR
|
|
415
|
-
|
|
416
|
-
---
|
|
417
|
-
|
|
418
|
-
Made with ❤️ by the Talos team
|
|
17
|
+
MIT
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@talosjs/mailer",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"module": "./dist/index.js",
|
|
5
5
|
"dependencies": {
|
|
6
|
-
"@talosjs/app-env": "^1.1.
|
|
7
|
-
"@talosjs/container": "^1.1.
|
|
8
|
-
"@talosjs/exception": "^1.1.
|
|
9
|
-
"@talosjs/http-status": "^1.1.
|
|
10
|
-
"@talosjs/translation": "^1.1.
|
|
6
|
+
"@talosjs/app-env": "^1.1.2",
|
|
7
|
+
"@talosjs/container": "^1.1.1",
|
|
8
|
+
"@talosjs/exception": "^1.1.1",
|
|
9
|
+
"@talosjs/http-status": "^1.1.1",
|
|
10
|
+
"@talosjs/translation": "^1.1.1",
|
|
11
11
|
"resend": "^6.4.2"
|
|
12
12
|
},
|
|
13
13
|
"exports": {
|
|
@@ -41,8 +41,8 @@
|
|
|
41
41
|
"scripts": {
|
|
42
42
|
"test": "bun test tests",
|
|
43
43
|
"build": "bunup",
|
|
44
|
-
"
|
|
45
|
-
"
|
|
44
|
+
"fmt": "bunx biome check --write",
|
|
45
|
+
"lint": "tsgo --noEmit && bunx biome lint"
|
|
46
46
|
},
|
|
47
47
|
"type": "module",
|
|
48
48
|
"types": "./dist/index.d.ts"
|