@push.rocks/smartmta 5.1.2 → 5.1.3

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/changelog.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # Changelog
2
2
 
3
+ ## 2026-02-11 - 5.1.3 - fix(docs)
4
+ clarify sendEmail default behavior and document automatic MX discovery and delivery modes
5
+
6
+ - Updated README to describe automatic MX record discovery and grouping behavior when using sendEmail() (MTA mode)
7
+ - Added a Delivery Modes section and API signature for sendEmail(mode) describing mta, forward, and process options
8
+ - Expanded examples to show multi-recipient delivery, explicit mode usage, and retained low-level sendOutboundEmail example
9
+
3
10
  ## 2026-02-11 - 5.1.2 - fix(readme)
4
11
  adjust ASCII architecture diagram alignment in README
5
12
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@push.rocks/smartmta",
3
- "version": "5.1.2",
3
+ "version": "5.1.3",
4
4
  "description": "A high-performance, enterprise-grade Mail Transfer Agent (MTA) built from scratch in TypeScript with Rust acceleration.",
5
5
  "keywords": [
6
6
  "mta",
package/readme.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @push.rocks/smartmta
2
2
 
3
- A high-performance, enterprise-grade Mail Transfer Agent (MTA) built from scratch in TypeScript with a Rust-powered SMTP engine — no nodemailer, no shortcuts. 🚀
3
+ A high-performance, enterprise-grade Mail Transfer Agent (MTA) built from scratch in TypeScript with a Rust-powered SMTP engine — no nodemailer, no shortcuts. Automatic MX record discovery means you just call `sendEmail()` and smartmta figures out where to deliver. 🚀
4
4
 
5
5
  ## Issue Reporting and Security
6
6
 
@@ -78,9 +78,10 @@ After installation, run `pnpm build` to compile the Rust binary (`mailer-bin`).
78
78
 
79
79
  **Data flow for outbound mail:**
80
80
 
81
- 1. 📝 TypeScript constructs the email and resolves DKIM keys for the sender domain
82
- 2. 🦀 Sends to Rust via IPC Rust builds the RFC 2822 message, signs with DKIM, and delivers via its SMTP client with connection pooling
83
- 3. 📬 Result (accepted/rejected recipients, server response) returned to TypeScript
81
+ 1. 📝 TypeScript constructs the email and calls `sendEmail()` (defaults to MTA mode)
82
+ 2. 🔍 MTA mode automatically resolves MX records for each recipient domain, sorts by priority, and groups recipients for efficient delivery
83
+ 3. 🦀 Sends to Rust via IPC — Rust builds the RFC 2822 message, signs with DKIM, and delivers via its SMTP client with connection pooling
84
+ 4. 📬 Result (accepted/rejected recipients, server response) returned to TypeScript
84
85
 
85
86
  ## Usage
86
87
 
@@ -169,9 +170,9 @@ await emailServer.start();
169
170
 
170
171
  > 🔒 **Note:** `start()` will throw if the Rust binary is not compiled. Run `pnpm build` first.
171
172
 
172
- ### 📧 Sending Outbound Emails
173
+ ### 📧 Sending Emails (Automatic MX Discovery)
173
174
 
174
- All outbound email delivery goes through the Rust SMTP client, accessed via `UnifiedEmailServer.sendOutboundEmail()`. The Rust client handles connection pooling, TLS negotiation, and DKIM signing automatically:
175
+ The recommended way to send email is `sendEmail()`. It defaults to **MTA mode**, which automatically resolves MX records for each recipient domain via DNS you don't need to know the destination mail server:
175
176
 
176
177
  ```typescript
177
178
  import { Email, UnifiedEmailServer } from '@push.rocks/smartmta';
@@ -179,8 +180,7 @@ import { Email, UnifiedEmailServer } from '@push.rocks/smartmta';
179
180
  // Build an email
180
181
  const email = new Email({
181
182
  from: 'sender@example.com',
182
- to: ['recipient@example.com'],
183
- cc: ['cc@example.com'],
183
+ to: ['alice@gmail.com', 'bob@company.org'],
184
184
  subject: 'Hello from smartmta! 🚀',
185
185
  text: 'Plain text body',
186
186
  html: '<h1>Hello!</h1><p>HTML body with <strong>formatting</strong></p>',
@@ -194,7 +194,50 @@ const email = new Email({
194
194
  ],
195
195
  });
196
196
 
197
- // Send via the Rust SMTP client (connection pooling, TLS, DKIM signing)
197
+ // Send MTA mode auto-discovers MX servers for gmail.com and company.org
198
+ const emailId = await emailServer.sendEmail(email);
199
+
200
+ // Optionally specify a delivery mode explicitly
201
+ const emailId2 = await emailServer.sendEmail(email, 'mta');
202
+ ```
203
+
204
+ In MTA mode, smartmta:
205
+ - 🔍 Resolves MX records for each recipient domain (e.g. `gmail.com`, `company.org`)
206
+ - 📊 Sorts MX hosts by priority (lowest = highest priority per RFC 5321)
207
+ - 🔄 Tries each MX host in order until delivery succeeds
208
+ - 🌐 Falls back to the domain's A record if no MX records exist
209
+ - 📦 Groups recipients by domain for efficient batch delivery
210
+ - 🔑 Signs outbound mail with DKIM automatically
211
+
212
+ ### 📮 Delivery Modes
213
+
214
+ `sendEmail()` accepts a mode parameter that controls how the email is delivered:
215
+
216
+ ```typescript
217
+ public async sendEmail(
218
+ email: Email,
219
+ mode: EmailProcessingMode = 'mta', // 'mta' | 'forward' | 'process'
220
+ route?: IEmailRoute,
221
+ options?: {
222
+ skipSuppressionCheck?: boolean;
223
+ ipAddress?: string;
224
+ isTransactional?: boolean;
225
+ }
226
+ ): Promise<string>
227
+ ```
228
+
229
+ | Mode | Description |
230
+ |---|---|
231
+ | `mta` (default) | **Auto MX discovery** — resolves MX records via DNS, delivers directly to the recipient's mail server. No relay configuration needed. |
232
+ | `forward` | **Relay delivery** — forwards the email to a configured SMTP host (e.g. an internal mail gateway or third-party relay). |
233
+ | `process` | **Scan + deliver** — runs the content scanning / security pipeline first, then delivers via auto MX resolution. |
234
+
235
+ ### 📬 Direct SMTP Delivery (Low-Level)
236
+
237
+ For cases where you know the exact target SMTP server (e.g. relaying to a specific host), use the lower-level `sendOutboundEmail()`:
238
+
239
+ ```typescript
240
+ // Send directly to a known SMTP server (bypasses MX resolution)
198
241
  const result = await emailServer.sendOutboundEmail('smtp.example.com', 587, email, {
199
242
  auth: { user: 'sender@example.com', pass: 'your-password' },
200
243
  dkimDomain: 'example.com',