@astralibx/email-account-manager 2.0.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/README.md +118 -0
- package/dist/index.d.mts +1049 -0
- package/dist/index.d.ts +1049 -0
- package/dist/index.js +3044 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +2999 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +68 -0
package/README.md
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
# @astralibx/email-account-manager
|
|
2
|
+
|
|
3
|
+
A production-ready, multi-account email infrastructure library for Node.js. Manages multiple SMTP accounts (Gmail, AWS SES) with automatic health tracking, account warmup, capacity-based rotation, BullMQ job queues, draft approval workflows, IMAP bounce detection, SES webhook processing, and built-in unsubscribe handling. Plug it into any Express app with three routers and a single factory call.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @astralibx/email-account-manager
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
### Peer Dependencies
|
|
12
|
+
|
|
13
|
+
| Package | Required |
|
|
14
|
+
|---------|----------|
|
|
15
|
+
| `express` | Yes |
|
|
16
|
+
| `mongoose` | Yes |
|
|
17
|
+
| `ioredis` | Yes |
|
|
18
|
+
| `bullmq` | Yes |
|
|
19
|
+
| `nodemailer` | Yes |
|
|
20
|
+
| `imapflow` | Optional (IMAP bounce checking) |
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
npm install express mongoose ioredis bullmq nodemailer
|
|
24
|
+
# Optional: npm install imapflow
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Quick Start
|
|
28
|
+
|
|
29
|
+
```ts
|
|
30
|
+
import express from 'express';
|
|
31
|
+
import mongoose from 'mongoose';
|
|
32
|
+
import Redis from 'ioredis';
|
|
33
|
+
import { createEmailAccountManager } from '@astralibx/email-account-manager';
|
|
34
|
+
|
|
35
|
+
const app = express();
|
|
36
|
+
app.use(express.json());
|
|
37
|
+
|
|
38
|
+
const db = await mongoose.createConnection('mongodb://localhost:27017/myapp');
|
|
39
|
+
const redis = new Redis();
|
|
40
|
+
|
|
41
|
+
const eam = createEmailAccountManager({
|
|
42
|
+
db: { connection: db },
|
|
43
|
+
redis: { connection: redis },
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
// Admin API (protect with your own auth middleware)
|
|
47
|
+
app.use('/api/email', eam.routes);
|
|
48
|
+
|
|
49
|
+
// SES webhook endpoint (public, signature-verified)
|
|
50
|
+
app.use('/webhooks/ses', eam.webhookRoutes.ses);
|
|
51
|
+
|
|
52
|
+
// Unsubscribe pages (public)
|
|
53
|
+
app.use('/unsubscribe', eam.unsubscribeRoutes);
|
|
54
|
+
|
|
55
|
+
// Send an email programmatically
|
|
56
|
+
const result = await eam.smtp.send({
|
|
57
|
+
to: 'recipient@example.com',
|
|
58
|
+
subject: 'Hello',
|
|
59
|
+
html: '<h1>Welcome!</h1>',
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
console.log(result); // { success: true, messageId: '...' }
|
|
63
|
+
|
|
64
|
+
app.listen(3000);
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## Features
|
|
68
|
+
|
|
69
|
+
- **Multi-account management** -- Gmail and AWS SES providers with credential storage and status tracking. [Details](docs/account-management.md)
|
|
70
|
+
- **Health tracking** -- Automatic scoring (+1/-5/-10) with auto-disable on threshold breach. [Details](docs/health-tracking.md)
|
|
71
|
+
- **Account warmup** -- Phased volume ramp-up with configurable schedules stored per-account. [Details](docs/warmup-system.md)
|
|
72
|
+
- **Capacity-based rotation** -- Health-weighted account selection with daily limit enforcement. [Details](docs/capacity-selection.md)
|
|
73
|
+
- **Reliable sending** -- BullMQ queues with retries, dev mode redirect, and per-account SMTP. [Details](docs/email-sending.md)
|
|
74
|
+
- **Draft approval workflow** -- Create, review, approve/reject, bulk operations, send window spread. [Details](docs/draft-approval.md)
|
|
75
|
+
- **Unsubscribe handling** -- HMAC tokens, styled confirmation page, RFC 8058 one-click support. [Details](docs/unsubscribe.md)
|
|
76
|
+
- **SES webhooks** -- SNS signature verification, bounce/complaint/delivery/open/click processing. [Details](docs/ses-webhooks.md)
|
|
77
|
+
- **IMAP bounce detection** -- Gmail IMAP polling with bounce classification. [Details](docs/imap-bounce-checking.md)
|
|
78
|
+
- **Global settings** -- Runtime-adjustable config stored in MongoDB with in-memory caching. [Details](docs/global-settings.md)
|
|
79
|
+
- **Error classes** -- Typed errors with codes for every failure scenario. [Details](docs/error-handling.md)
|
|
80
|
+
|
|
81
|
+
## Architecture
|
|
82
|
+
|
|
83
|
+
The library exposes three Express routers from a single factory call:
|
|
84
|
+
|
|
85
|
+
| Router | Purpose | Access |
|
|
86
|
+
|--------|---------|--------|
|
|
87
|
+
| `eam.routes` | Admin API -- accounts, drafts, settings, queues | Protected (add your auth middleware) |
|
|
88
|
+
| `eam.webhookRoutes.ses` | SES/SNS event receiver | Public (SNS signature verified) |
|
|
89
|
+
| `eam.unsubscribeRoutes` | Unsubscribe confirmation pages | Public |
|
|
90
|
+
|
|
91
|
+
All services are also available programmatically via the returned `eam` object. See [Programmatic API](docs/programmatic-api.md).
|
|
92
|
+
|
|
93
|
+
## Documentation
|
|
94
|
+
|
|
95
|
+
| Document | Description |
|
|
96
|
+
|----------|-------------|
|
|
97
|
+
| [Configuration](docs/configuration.md) | Full config reference -- db, redis, ses, unsubscribe, options, hooks, logger |
|
|
98
|
+
| [Account Management](docs/account-management.md) | Adding accounts, providers (Gmail/SES), status lifecycle |
|
|
99
|
+
| [Health Tracking](docs/health-tracking.md) | Scoring rules, auto-disable triggers, thresholds |
|
|
100
|
+
| [Warmup System](docs/warmup-system.md) | Phases, daily limits, progression, DB-driven schedules |
|
|
101
|
+
| [Capacity Selection](docs/capacity-selection.md) | Best account selection, rotation algorithm |
|
|
102
|
+
| [Email Sending](docs/email-sending.md) | SMTP service, BullMQ queues, dev mode redirect |
|
|
103
|
+
| [Draft & Approval](docs/draft-approval.md) | Creating drafts, approval workflow, bulk operations, send window |
|
|
104
|
+
| [Unsubscribe](docs/unsubscribe.md) | HMAC tokens, confirmation page, one-click, RFC 8058 |
|
|
105
|
+
| [SES Webhooks](docs/ses-webhooks.md) | SNS setup, signature verification, event processing |
|
|
106
|
+
| [IMAP Bounce Checking](docs/imap-bounce-checking.md) | Gmail IMAP polling, bounce classification |
|
|
107
|
+
| [Global Settings](docs/global-settings.md) | Runtime settings, sections, caching, defaults |
|
|
108
|
+
| [API Routes](docs/api-routes.md) | All 3 routers with endpoint tables |
|
|
109
|
+
| [Programmatic API](docs/programmatic-api.md) | Using services directly via the EmailAccountManager interface |
|
|
110
|
+
| [Error Handling](docs/error-handling.md) | All error classes with codes |
|
|
111
|
+
|
|
112
|
+
## Security Notes
|
|
113
|
+
|
|
114
|
+
**Credential storage**: SMTP and IMAP passwords (`smtp.pass`, `imap.pass`) are stored as plaintext in MongoDB. You should encrypt these values at the application layer before passing them to this library, and decrypt them after retrieval. A built-in encryption layer is planned for a future version.
|
|
115
|
+
|
|
116
|
+
## License
|
|
117
|
+
|
|
118
|
+
MIT
|