@unireq/smtp 0.0.1 → 1.0.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 +101 -0
- package/package.json +2 -2
package/README.md
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
# @unireq/smtp
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@unireq/smtp)
|
|
4
|
+
[](https://opensource.org/licenses/MIT)
|
|
5
|
+
|
|
6
|
+
SMTP transport with a pluggable connector architecture. Ships with a default connector powered by `nodemailer`, but you can bring your own implementation (BYOC).
|
|
7
|
+
|
|
8
|
+
## Installation
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
pnpm add @unireq/smtp
|
|
12
|
+
|
|
13
|
+
# For the default connector (optional peer dependency)
|
|
14
|
+
pnpm add nodemailer
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Quick Start
|
|
18
|
+
|
|
19
|
+
```typescript
|
|
20
|
+
import { client } from '@unireq/core';
|
|
21
|
+
import { smtp } from '@unireq/smtp';
|
|
22
|
+
|
|
23
|
+
const { transport } = smtp('smtp://user:pass@smtp.gmail.com:587');
|
|
24
|
+
const mail = client(transport);
|
|
25
|
+
|
|
26
|
+
const result = await mail.post('/', {
|
|
27
|
+
from: 'me@gmail.com',
|
|
28
|
+
to: 'you@example.com',
|
|
29
|
+
subject: 'Hello!',
|
|
30
|
+
text: 'This is a test email.',
|
|
31
|
+
});
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Features
|
|
35
|
+
|
|
36
|
+
| Category | Symbols | Purpose |
|
|
37
|
+
| --- | --- | --- |
|
|
38
|
+
| Transport | `smtp(uri?, connector?)` | SMTP/SMTPS transport factory |
|
|
39
|
+
| Default connector | `NodemailerConnector` | Implementation using `nodemailer` |
|
|
40
|
+
| Types | `EmailMessage`, `EmailAttachment`, `SendResult` | Email composition structures |
|
|
41
|
+
|
|
42
|
+
## Email Message Format
|
|
43
|
+
|
|
44
|
+
```typescript
|
|
45
|
+
const message = {
|
|
46
|
+
from: 'sender@example.com',
|
|
47
|
+
to: 'recipient@example.com',
|
|
48
|
+
subject: 'Email Subject',
|
|
49
|
+
text: 'Plain text body',
|
|
50
|
+
html: '<h1>HTML body</h1>',
|
|
51
|
+
cc: 'cc@example.com',
|
|
52
|
+
bcc: ['bcc1@example.com'],
|
|
53
|
+
attachments: [
|
|
54
|
+
{ filename: 'doc.pdf', content: buffer, contentType: 'application/pdf' },
|
|
55
|
+
],
|
|
56
|
+
};
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## Gmail Authentication
|
|
60
|
+
|
|
61
|
+
### App Password (Development)
|
|
62
|
+
|
|
63
|
+
```typescript
|
|
64
|
+
const { transport } = smtp('smtp://your@gmail.com:xxxx-xxxx-xxxx-xxxx@smtp.gmail.com:587');
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### OAuth2 (Production)
|
|
68
|
+
|
|
69
|
+
```typescript
|
|
70
|
+
const { transport } = smtp('smtp://user@gmail.com@smtp.gmail.com:587', {
|
|
71
|
+
oauth2: {
|
|
72
|
+
clientId: 'your-client-id.apps.googleusercontent.com',
|
|
73
|
+
clientSecret: 'your-client-secret',
|
|
74
|
+
refreshToken: 'your-refresh-token',
|
|
75
|
+
},
|
|
76
|
+
});
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
## Bring Your Own Connector
|
|
80
|
+
|
|
81
|
+
```typescript
|
|
82
|
+
import type { SMTPConnector, SMTPSession } from '@unireq/smtp';
|
|
83
|
+
|
|
84
|
+
class MySMTPConnector implements SMTPConnector {
|
|
85
|
+
readonly capabilities = { smtp: true, smtps: true, starttls: true, oauth2: false, html: true, attachments: true };
|
|
86
|
+
|
|
87
|
+
async connect(uri: string): Promise<SMTPSession> { /* ... */ }
|
|
88
|
+
async request(session, context) { /* ... */ }
|
|
89
|
+
disconnect(session) { /* ... */ }
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const { transport } = smtp('smtp://server.com', new MySMTPConnector());
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
## Documentation
|
|
96
|
+
|
|
97
|
+
Full documentation available at [unireq.dev](https://oorabona.github.io/unireq/)
|
|
98
|
+
|
|
99
|
+
## License
|
|
100
|
+
|
|
101
|
+
MIT
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unireq/smtp",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "SMTP transport for unireq using nodemailer",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"author": "Olivier Orabona",
|
|
18
18
|
"license": "MIT",
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@unireq/core": "
|
|
20
|
+
"@unireq/core": "1.0.1"
|
|
21
21
|
},
|
|
22
22
|
"peerDependencies": {
|
|
23
23
|
"nodemailer": "^7.0.12"
|