2026-02-10 16:25:55 +00:00
# @push.rocks/smartmta
2025-10-24 08:09:29 +00:00
2026-02-10 22:04:56 +00:00
A high-performance, enterprise-grade Mail Transfer Agent (MTA) built from scratch in TypeScript with a Rust-powered SMTP engine — no nodemailer, no shortcuts. 🚀
2025-10-24 08:09:29 +00:00
2026-02-10 16:25:55 +00:00
## Issue Reporting and Security
2025-10-24 08:09:29 +00:00
2026-02-10 16:25:55 +00:00
For reporting bugs, issues, or security vulnerabilities, please visit [community.foss.global/ ](https://community.foss.global/ ). This is the central community hub for all issue reporting. Developers who sign and comply with our contribution agreement and go through identification can also get a [code.foss.global/ ](https://code.foss.global/ ) account to submit Pull Requests directly.
2025-10-24 08:09:29 +00:00
2026-02-10 16:25:55 +00:00
## Install
2025-10-24 08:09:29 +00:00
2026-02-10 16:25:55 +00:00
```bash
pnpm install @push .rocks/smartmta
# or
npm install @push .rocks/smartmta
```
2025-10-24 08:09:29 +00:00
2026-02-10 22:04:56 +00:00
After installation, run `pnpm build` to compile the Rust binary (`mailer-bin` ). The Rust binary is **required ** — `smartmta` will not start without it.
2026-02-10 16:25:55 +00:00
## Overview
2025-10-24 08:09:29 +00:00
2026-02-10 22:04:56 +00:00
`@push.rocks/smartmta` is a **complete mail server solution ** — SMTP server, SMTP client, email security, content scanning, and delivery management — all built with a custom SMTP implementation. The SMTP server itself runs as a Rust binary for maximum performance, communicating with the TypeScript orchestration layer via IPC.
2026-02-10 16:25:55 +00:00
2026-02-10 22:04:56 +00:00
### ⚡ What's Inside
2026-02-10 16:25:55 +00:00
| Module | What It Does |
|---|---|
2026-02-10 22:04:56 +00:00
| **Rust SMTP Server ** | High-performance SMTP engine written in Rust — TCP/TLS listener, STARTTLS, AUTH, pipelining, per-connection rate limiting |
2026-02-10 16:25:55 +00:00
| **SMTP Client ** | Outbound delivery with connection pooling, retry logic, TLS negotiation |
2026-02-10 22:04:56 +00:00
| **DKIM ** | Key generation, signing, and verification — per domain, with automatic rotation |
| **SPF ** | Full SPF record validation via Rust |
2026-02-10 16:25:55 +00:00
| **DMARC ** | Policy enforcement and verification |
| **Email Router ** | Pattern-based routing with priority, forward/deliver/reject/process actions |
2026-02-10 22:04:56 +00:00
| **Bounce Manager ** | Automatic bounce detection via Rust, classification (hard/soft), and suppression tracking |
| **Content Scanner ** | Spam, phishing, malware, XSS, and suspicious link detection — powered by Rust |
| **IP Reputation ** | DNSBL checks, proxy/TOR/VPN detection, risk scoring via Rust |
2026-02-10 16:57:14 +00:00
| **Rate Limiter ** | Hierarchical rate limiting (global, per-domain, per-IP) |
2026-02-10 16:25:55 +00:00
| **Delivery Queue ** | Persistent queue with exponential backoff retry |
| **Template Engine ** | Email templates with variable substitution |
| **Domain Registry ** | Multi-domain management with per-domain configuration |
| **DNS Manager ** | Automatic DNS record management with Cloudflare API integration |
2026-02-10 22:04:56 +00:00
| **Rust Security Bridge ** | All security ops (DKIM+SPF+DMARC+DNSBL+content scanning) run in Rust via IPC |
2026-02-10 16:25:55 +00:00
2026-02-10 22:04:56 +00:00
### 🏗️ Architecture
2025-10-24 08:09:29 +00:00
```
2026-02-10 22:04:56 +00:00
┌──────────────────────────────────────────────────────────────┐
│ UnifiedEmailServer │
│ (orchestrates all components, emits events) │
├───────────┬───────────┬──────────────┬───────────────────────┤
│ Email │ Security │ Delivery │ Configuration │
│ Router │ Stack │ System │ │
│ ┌──────┐ │ ┌───────┐ │ ┌──────────┐ │ ┌────────────────┐ │
│ │Match │ │ │ DKIM │ │ │ Queue │ │ │ DomainRegistry │ │
│ │Route │ │ │ SPF │ │ │ Rate Lim │ │ │ DnsManager │ │
│ │ Act │ │ │ DMARC │ │ │ SMTP Cli │ │ │ DKIMCreator │ │
│ └──────┘ │ │ IPRep │ │ │ Retry │ │ │ Templates │ │
│ │ │ Scan │ │ └──────────┘ │ └────────────────┘ │
│ │ └───────┘ │ │ │
├───────────┴───────────┴──────────────┴───────────────────────┤
│ Rust Security Bridge (smartrust IPC) │
├──────────────────────────────────────────────────────────────┤
│ Rust Acceleration Layer │
│ ┌──────────────┐ ┌───────────────┐ ┌──────────────────┐ │
│ │ mailer-smtp │ │mailer-security│ │ mailer-core │ │
│ │ SMTP Server │ │DKIM/SPF/DMARC │ │ Types/Validation │ │
│ │ TLS/AUTH │ │IP Rep/Content │ │ MIME/Bounce │ │
│ └──────────────┘ └───────────────┘ └──────────────────┘ │
└──────────────────────────────────────────────────────────────┘
2025-10-24 08:09:29 +00:00
```
2026-02-10 22:04:56 +00:00
**Data flow for inbound mail:**
1. Rust SMTP server accepts the connection and handles the SMTP protocol
2. On `DATA` completion, Rust emits an `emailReceived` event via IPC
3. TypeScript processes the email (routing, scanning, delivery decisions)
4. TypeScript sends the processing result back to Rust via IPC
5. Rust sends the final SMTP response to the client
2026-02-10 16:25:55 +00:00
## Usage
2025-10-24 08:09:29 +00:00
2026-02-10 22:04:56 +00:00
### 🚀 Setting Up the Email Server
2025-10-24 08:09:29 +00:00
2026-02-10 22:04:56 +00:00
The central entry point is `UnifiedEmailServer` , which orchestrates the Rust SMTP server, routing, security, and delivery:
2025-10-24 08:09:29 +00:00
2026-02-10 16:25:55 +00:00
```typescript
import { UnifiedEmailServer } from '@push .rocks/smartmta';
2025-10-24 08:09:29 +00:00
2026-02-10 16:25:55 +00:00
const emailServer = new UnifiedEmailServer(dcRouterRef, {
2026-02-10 22:04:56 +00:00
// Ports to listen on (465 = implicit TLS, 25/587 = STARTTLS)
2026-02-10 16:25:55 +00:00
ports: [25, 587, 465],
hostname: 'mail.example.com',
2026-02-10 22:04:56 +00:00
// Multi-domain configuration
2026-02-10 16:25:55 +00:00
domains: [
{
domain: 'example.com',
dnsMode: 'external-dns',
dkim: {
selector: 'default',
keySize: 2048,
rotateKeys: true,
rotationInterval: 90,
},
rateLimits: {
2026-02-10 22:04:56 +00:00
outbound: { messagesPerMinute: 100 },
inbound: { messagesPerMinute: 200, connectionsPerIp: 20 },
2026-02-10 16:25:55 +00:00
},
},
],
2026-02-10 22:04:56 +00:00
// Routing rules (evaluated by priority, highest first)
2026-02-10 16:25:55 +00:00
routes: [
{
name: 'catch-all-forward',
priority: 10,
match: {
recipients: '*@example .com',
},
action: {
type: 'forward',
forward: {
host: 'internal-mail.example.com',
port: 25,
},
},
},
{
name: 'reject-spam-senders',
priority: 100,
match: {
senders: '*@spamdomain .com',
},
action: {
type: 'reject',
reject: {
code: 550,
message: 'Sender rejected by policy',
},
},
},
],
2026-02-10 22:04:56 +00:00
// Authentication settings for the SMTP server
2026-02-10 16:25:55 +00:00
auth: {
required: false,
methods: ['PLAIN', 'LOGIN'],
users: [{ username: 'outbound', password: 'secret' }],
},
2026-02-10 22:04:56 +00:00
// TLS certificates
2026-02-10 16:25:55 +00:00
tls: {
certPath: '/etc/ssl/mail.crt',
keyPath: '/etc/ssl/mail.key',
},
2026-02-10 22:04:56 +00:00
2026-02-10 16:25:55 +00:00
maxMessageSize: 25 * 1024 * 1024, // 25 MB
maxClients: 500,
});
2026-02-10 22:04:56 +00:00
// start() boots the Rust SMTP server, security bridge, DNS records, and delivery queue
2026-02-10 16:25:55 +00:00
await emailServer.start();
2025-10-24 08:09:29 +00:00
```
2026-02-10 22:04:56 +00:00
> 🔒 **Note:** `start()` will throw if the Rust binary is not compiled. Run `pnpm build` first.
### 📧 Sending Emails with the SMTP Client
2025-10-24 08:09:29 +00:00
2026-02-10 16:25:55 +00:00
Create and send emails using the built-in SMTP client with connection pooling:
2025-10-24 08:09:29 +00:00
2026-02-10 16:25:55 +00:00
```typescript
2026-02-10 22:04:56 +00:00
import { Email, Delivery } from '@push .rocks/smartmta';
2025-10-24 08:09:29 +00:00
2026-02-10 16:25:55 +00:00
// Create a client with connection pooling
2026-02-10 22:04:56 +00:00
const client = Delivery.smtpClientMod.createSmtpClient({
2026-02-10 16:25:55 +00:00
host: 'smtp.example.com',
port: 587,
secure: false, // will upgrade via STARTTLS
pool: true,
maxConnections: 5,
auth: {
user: 'sender@example .com',
pass: 'your-password',
},
});
2025-10-24 08:09:29 +00:00
2026-02-10 16:25:55 +00:00
// Build an email
const email = new Email({
from: 'sender@example .com',
to: ['recipient@example .com'],
cc: ['cc@example .com'],
subject: 'Hello from smartmta!',
text: 'Plain text body',
html: '<h1>Hello!</h1><p>HTML body with <strong>formatting</strong></p>',
priority: 'high',
attachments: [
{
filename: 'report.pdf',
content: pdfBuffer,
contentType: 'application/pdf',
},
],
});
2025-10-24 08:09:29 +00:00
2026-02-10 16:25:55 +00:00
// Send it
const result = await client.sendMail(email);
console.log(`Message sent: ${result.messageId}` );
```
2025-10-24 08:09:29 +00:00
2026-02-10 22:04:56 +00:00
Additional client factories are available:
```typescript
// Pooled client for high-throughput scenarios
const pooled = Delivery.smtpClientMod.createPooledSmtpClient({ /* ... */ });
// Optimized for bulk sending
const bulk = Delivery.smtpClientMod.createBulkSmtpClient({ /* ... */ });
// Optimized for transactional emails
const transactional = Delivery.smtpClientMod.createTransactionalSmtpClient({ /* ... */ });
```
### 🔑 DKIM Signing
2025-10-24 08:09:29 +00:00
2026-02-10 22:04:56 +00:00
DKIM key management is handled by `DKIMCreator` , which generates, stores, and rotates keys per domain. Signing is performed automatically by `UnifiedEmailServer` during outbound delivery:
2025-10-24 08:09:29 +00:00
2026-02-10 16:25:55 +00:00
```typescript
import { DKIMCreator } from '@push .rocks/smartmta';
2025-10-24 08:09:29 +00:00
2026-02-10 16:25:55 +00:00
const dkimCreator = new DKIMCreator('/path/to/keys');
2025-10-24 08:09:29 +00:00
2026-02-10 16:25:55 +00:00
// Auto-generate keys if they don't exist
await dkimCreator.handleDKIMKeysForDomain('example.com');
2025-10-24 08:09:29 +00:00
2026-02-10 16:25:55 +00:00
// Get the DNS record you need to publish
const dnsRecord = await dkimCreator.getDNSRecordForDomain('example.com');
console.log(dnsRecord);
2026-02-10 16:57:14 +00:00
// -> { type: 'TXT', name: 'default._domainkey.example.com', value: 'v=DKIM1; k=rsa; p=...' }
// Check if keys need rotation
const needsRotation = await dkimCreator.needsRotation('example.com', 'default', 90);
if (needsRotation) {
const newSelector = await dkimCreator.rotateDkimKeys('example.com', 'default', 2048);
console.log(`Rotated to selector: ${newSelector}` );
}
2025-10-24 08:09:29 +00:00
```
2026-02-10 22:04:56 +00:00
When `UnifiedEmailServer.start()` is called, DKIM signing is applied to all outbound mail automatically using the Rust security bridge's `signDkim()` method for maximum performance.
2026-02-10 16:57:14 +00:00
2026-02-10 22:04:56 +00:00
### 🛡️ Email Authentication (SPF, DKIM, DMARC)
2025-10-24 08:09:29 +00:00
2026-02-10 22:04:56 +00:00
Verify incoming emails against all three authentication standards. All verification is powered by the Rust binary:
2025-10-24 08:09:29 +00:00
2026-02-10 16:25:55 +00:00
```typescript
import { DKIMVerifier, SpfVerifier, DmarcVerifier } from '@push .rocks/smartmta';
2025-10-24 08:09:29 +00:00
2026-02-10 16:57:14 +00:00
// SPF verification — first arg is an Email object
2026-02-10 16:25:55 +00:00
const spfVerifier = new SpfVerifier();
2026-02-10 16:57:14 +00:00
const spfResult = await spfVerifier.verify(email, senderIP, heloDomain);
// -> { result: 'pass' | 'fail' | 'softfail' | 'neutral' | 'none' | 'temperror' | 'permerror',
// domain: string, ip: string }
2025-10-24 08:09:29 +00:00
2026-02-10 22:04:56 +00:00
// DKIM verification — takes raw email content
2026-02-10 16:25:55 +00:00
const dkimVerifier = new DKIMVerifier();
const dkimResult = await dkimVerifier.verify(rawEmailContent);
2025-10-24 08:09:29 +00:00
2026-02-10 16:57:14 +00:00
// DMARC verification — first arg is an Email object
2026-02-10 16:25:55 +00:00
const dmarcVerifier = new DmarcVerifier();
2026-02-10 16:57:14 +00:00
const dmarcResult = await dmarcVerifier.verify(email, spfResult, dkimResult);
// -> { action: 'pass' | 'quarantine' | 'reject', hasDmarc: boolean,
// spfDomainAligned: boolean, dkimDomainAligned: boolean, ... }
2025-10-24 08:09:29 +00:00
```
2026-02-10 22:04:56 +00:00
### 🔀 Email Routing
2025-10-24 08:09:29 +00:00
2026-02-10 22:04:56 +00:00
Pattern-based routing engine with priority ordering and flexible match criteria. Routes are evaluated by priority (highest first):
2026-02-10 16:25:55 +00:00
```typescript
import { EmailRouter } from '@push .rocks/smartmta';
const router = new EmailRouter([
{
name: 'admin-mail',
priority: 100,
match: {
recipients: 'admin@example .com',
authenticated: true,
},
action: {
type: 'deliver',
},
},
{
name: 'external-forward',
priority: 50,
match: {
recipients: '*@example .com',
sizeRange: { max: 10 * 1024 * 1024 }, // under 10MB
},
action: {
type: 'forward',
forward: {
host: 'backend-mail.internal',
port: 25,
preserveHeaders: true,
},
},
},
{
name: 'process-with-scanning',
priority: 10,
match: {
recipients: '*@*',
},
action: {
type: 'process',
process: {
scan: true,
dkim: true,
queue: 'normal',
},
},
},
]);
2025-10-24 08:09:29 +00:00
2026-02-10 16:57:14 +00:00
// Evaluate routes against an email context
const matchedRoute = await router.evaluateRoutes(emailContext);
2025-10-24 08:09:29 +00:00
```
2026-02-10 22:04:56 +00:00
**Match criteria available:**
2025-10-24 08:09:29 +00:00
2026-02-10 22:04:56 +00:00
| Criterion | Description |
|---|---|
| `recipients` | Glob patterns for recipient addresses (`*@example.com` ) |
| `senders` | Glob patterns for sender addresses |
| `clientIp` | IP addresses or CIDR ranges |
| `authenticated` | Require authentication status |
| `headers` | Match specific headers (string or RegExp) |
| `sizeRange` | Message size constraints (`{ min?, max? }` ) |
| `subject` | Subject line pattern (string or RegExp) |
| `hasAttachments` | Filter by attachment presence |
### 🔍 Content Scanning
Built-in content scanner for detecting spam, phishing, malware, and other threats. Text pattern scanning runs in Rust for performance; binary attachment scanning (PE headers, VBA macros) runs in TypeScript:
2025-10-24 08:09:29 +00:00
2026-02-10 16:25:55 +00:00
```typescript
import { ContentScanner } from '@push .rocks/smartmta';
const scanner = new ContentScanner({
scanSubject: true,
scanBody: true,
scanAttachments: true,
blockExecutables: true,
blockMacros: true,
minThreatScore: 30,
highThreatScore: 70,
customRules: [
{
pattern: /bitcoin.*wallet/i,
type: 'scam',
score: 80,
description: 'Cryptocurrency scam pattern',
},
],
});
2025-10-24 08:09:29 +00:00
2026-02-10 16:57:14 +00:00
const result = await scanner.scanEmail(email);
// -> { isClean: false, threatScore: 85, threatType: 'phishing', scannedElements: [...] }
2025-10-24 08:09:29 +00:00
```
2026-02-10 22:04:56 +00:00
### 🌐 IP Reputation Checking
2025-10-24 08:09:29 +00:00
2026-02-10 22:04:56 +00:00
Check sender IP addresses against DNSBL blacklists and classify IP types. DNSBL lookups run in Rust:
2025-10-24 08:09:29 +00:00
2026-02-10 16:25:55 +00:00
```typescript
import { IPReputationChecker } from '@push .rocks/smartmta';
2025-10-24 08:09:29 +00:00
2026-02-10 22:04:56 +00:00
const ipChecker = IPReputationChecker.getInstance({
2026-02-10 16:25:55 +00:00
enableDNSBL: true,
dnsblServers: ['zen.spamhaus.org', 'bl.spamcop.net'],
cacheTTL: 24 * 60 * 60 * 1000, // 24 hours
});
2025-10-24 08:09:29 +00:00
2026-02-10 16:25:55 +00:00
const reputation = await ipChecker.checkReputation('192.168.1.1');
2026-02-10 16:57:14 +00:00
// -> { score: 85, isSpam: false, isProxy: false, isTor: false, blacklists: [] }
2025-10-24 08:09:29 +00:00
```
2026-02-10 22:04:56 +00:00
### ⏱️ Rate Limiting
2026-02-10 16:57:14 +00:00
2026-02-10 22:04:56 +00:00
Hierarchical rate limiting to protect your server and maintain deliverability:
2025-10-24 08:09:29 +00:00
2026-02-10 16:25:55 +00:00
```typescript
2026-02-10 22:04:56 +00:00
import { Delivery } from '@push .rocks/smartmta';
const { UnifiedRateLimiter } = Delivery;
2025-10-24 08:09:29 +00:00
2026-02-10 16:25:55 +00:00
const rateLimiter = new UnifiedRateLimiter({
global: {
2026-02-10 16:57:14 +00:00
maxMessagesPerMinute: 1000,
maxRecipientsPerMessage: 500,
maxConnectionsPerIP: 20,
maxErrorsPerIP: 10,
maxAuthFailuresPerIP: 5,
blockDuration: 600000, // 10 minutes
2026-02-10 16:25:55 +00:00
},
2026-02-10 16:57:14 +00:00
domains: {
2026-02-10 16:25:55 +00:00
'example.com': {
2026-02-10 16:57:14 +00:00
maxMessagesPerMinute: 100,
maxRecipientsPerMessage: 50,
2026-02-10 16:25:55 +00:00
},
},
2025-10-24 08:09:29 +00:00
});
2026-02-10 16:57:14 +00:00
// Check before sending
const allowed = rateLimiter.checkMessageLimit(
'sender@example .com',
'192.168.1.1',
recipientCount,
undefined,
'example.com'
);
if (!allowed.allowed) {
console.log(`Rate limited: ${allowed.reason}` );
}
2025-10-24 08:09:29 +00:00
```
2026-02-10 22:04:56 +00:00
### 📬 Bounce Management
2025-10-24 08:09:29 +00:00
2026-02-10 22:04:56 +00:00
Automatic bounce detection (via Rust), classification, and suppression tracking:
2025-10-24 08:09:29 +00:00
2026-02-10 16:25:55 +00:00
```typescript
2026-02-10 22:04:56 +00:00
import { Core } from '@push .rocks/smartmta';
const { BounceManager } = Core;
2025-10-24 08:09:29 +00:00
2026-02-10 16:25:55 +00:00
const bounceManager = new BounceManager();
2025-10-24 08:09:29 +00:00
2026-02-10 16:25:55 +00:00
// Process an SMTP failure
const bounce = await bounceManager.processSmtpFailure(
'recipient@example .com',
'550 5.1.1 User unknown',
{ originalEmailId: 'msg-123' }
);
2026-02-10 16:57:14 +00:00
// -> { bounceType: 'invalid_recipient', bounceCategory: 'hard', ... }
// Check if an address is suppressed due to bounces
const suppressed = bounceManager.isEmailSuppressed('recipient@example .com');
2025-10-24 08:09:29 +00:00
2026-02-10 16:57:14 +00:00
// Manually manage the suppression list
bounceManager.addToSuppressionList('bad@example .com', 'repeated hard bounces');
bounceManager.removeFromSuppressionList('recovered@example .com');
2025-10-24 08:09:29 +00:00
```
2026-02-10 22:04:56 +00:00
### 📝 Email Templates
2025-10-24 08:09:29 +00:00
2026-02-10 22:04:56 +00:00
Template engine with variable substitution for transactional and notification emails:
2025-10-24 08:09:29 +00:00
2026-02-10 16:25:55 +00:00
```typescript
2026-02-10 22:04:56 +00:00
import { Core } from '@push .rocks/smartmta';
const { TemplateManager } = Core;
2025-10-24 08:09:29 +00:00
2026-02-10 16:25:55 +00:00
const templates = new TemplateManager({
from: 'noreply@example .com',
2026-02-10 22:04:56 +00:00
footerHtml: '<p>© 2026 Example Corp</p>',
2026-02-10 16:25:55 +00:00
});
2025-10-24 08:09:29 +00:00
2026-02-10 16:25:55 +00:00
// Register a template
templates.registerTemplate({
id: 'welcome',
name: 'Welcome Email',
description: 'Sent to new users',
from: 'welcome@example .com',
subject: 'Welcome, {{name}}!',
bodyHtml: '<h1>Welcome, {{name}}!</h1><p>Your account is ready.</p>',
bodyText: 'Welcome, {{name}}! Your account is ready.',
category: 'transactional',
});
2025-10-24 08:09:29 +00:00
2026-02-10 16:57:14 +00:00
// Create an Email object from the template
const email = await templates.createEmail('welcome', {
2026-02-10 16:25:55 +00:00
to: 'newuser@example .com',
variables: { name: 'Alice' },
});
```
2025-10-24 08:09:29 +00:00
2026-02-10 22:04:56 +00:00
### 🌍 DNS Management
2025-10-24 08:09:29 +00:00
2026-02-10 22:04:56 +00:00
DNS record management for email authentication is handled automatically by `UnifiedEmailServer` . When the server starts, it ensures MX, SPF, DKIM, and DMARC records are in place for all configured domains via the Cloudflare API:
2025-10-24 08:09:29 +00:00
2026-02-10 16:25:55 +00:00
```typescript
2026-02-10 16:57:14 +00:00
const emailServer = new UnifiedEmailServer(dcRouterRef, {
hostname: 'mail.example.com',
2026-02-10 16:25:55 +00:00
domains: [
{
domain: 'example.com',
dnsMode: 'external-dns', // managed via Cloudflare API
},
],
2026-02-10 16:57:14 +00:00
// ... other config
2026-02-10 16:25:55 +00:00
});
2025-10-24 08:09:29 +00:00
2026-02-10 22:04:56 +00:00
// DNS records are set up automatically on start:
// - MX records pointing to your mail server
// - SPF TXT records authorizing your server IP
// - DKIM TXT records with public keys from DKIMCreator
// - DMARC TXT records with your policy
2026-02-10 16:57:14 +00:00
await emailServer.start();
2026-02-10 16:25:55 +00:00
```
2025-10-24 08:09:29 +00:00
2026-02-10 22:04:56 +00:00
### 🦀 RustSecurityBridge
2025-10-24 08:09:29 +00:00
2026-02-10 22:04:56 +00:00
The `RustSecurityBridge` is the singleton that manages the Rust binary process. It handles security verification, content scanning, bounce detection, and the SMTP server lifecycle — all via `@push.rocks/smartrust` IPC:
2026-02-10 16:57:14 +00:00
```typescript
import { RustSecurityBridge } from '@push .rocks/smartmta';
const bridge = RustSecurityBridge.getInstance();
await bridge.start();
// Compound verification: DKIM + SPF + DMARC in a single IPC call
const securityResult = await bridge.verifyEmail({
rawMessage: rawEmailString,
ip: '203.0.113.10',
heloDomain: 'sender.example.com',
mailFrom: 'user@example .com',
});
// -> { dkim: [...], spf: { result, explanation }, dmarc: { result, policy } }
2026-02-10 22:04:56 +00:00
// Individual security operations
2026-02-10 16:57:14 +00:00
const dkimResults = await bridge.verifyDkim(rawEmailString);
const spfResult = await bridge.checkSpf({
ip: '203.0.113.10',
heloDomain: 'sender.example.com',
mailFrom: 'user@example .com',
});
const reputationResult = await bridge.checkIpReputation('203.0.113.10');
2026-02-10 22:04:56 +00:00
// DKIM signing
const signed = await bridge.signDkim({
email: rawEmailString,
domain: 'example.com',
selector: 'default',
privateKeyPem: privateKey,
});
// Content scanning
const scanResult = await bridge.scanContent({
subject: 'Win a free iPhone!!!',
body: '<a href="http://phishing.example.com">Click here</a>',
from: 'scammer@evil .com',
});
// Bounce detection
const bounceResult = await bridge.detectBounce({
subject: 'Delivery Status Notification (Failure)',
body: '550 5.1.1 User unknown',
from: 'mailer-daemon@example .com',
});
2026-02-10 16:57:14 +00:00
await bridge.stop();
```
2026-02-10 22:04:56 +00:00
> ⚠️ **Important:** The Rust bridge is **mandatory**. There are no TypeScript fallbacks. If the Rust binary is unavailable, `UnifiedEmailServer.start()` will throw an error.
## 🦀 Rust Acceleration Layer
Performance-critical operations are implemented in Rust and communicate with the TypeScript runtime via `@push.rocks/smartrust` (JSON-over-stdin/stdout IPC). The Rust workspace lives at `rust/` with five crates:
| Crate | Status | Purpose |
|---|---|---|
| `mailer-core` | ✅ Complete (26 tests) | Email types, validation, MIME building, bounce detection |
| `mailer-security` | ✅ Complete (22 tests) | DKIM sign/verify, SPF, DMARC, IP reputation/DNSBL, content scanning |
| `mailer-smtp` | ✅ Complete (72 tests) | Full SMTP protocol engine — TCP/TLS server, STARTTLS, AUTH, pipelining, rate limiting |
| `mailer-bin` | ✅ Complete | CLI + smartrust IPC bridge — security, content scanning, SMTP server lifecycle |
| `mailer-napi` | 🔜 Planned | Native Node.js addon (N-API) |
### What Runs in Rust
| Operation | Runs In | Why |
|---|---|---|
| SMTP server (port listening, protocol, TLS) | Rust | Performance, memory safety, zero-copy parsing |
| DKIM signing & verification | Rust | Crypto-heavy, benefits from native speed |
| SPF validation | Rust | DNS lookups with async resolver |
| DMARC policy checking | Rust | Integrates with SPF/DKIM results |
| IP reputation / DNSBL | Rust | Parallel DNS queries |
| Content scanning (text patterns) | Rust | Regex engine performance |
| Bounce detection (pattern matching) | Rust | Regex engine performance |
| Email validation & MIME building | Rust | Parsing performance |
| Binary attachment scanning | TypeScript | Buffer data too large for IPC |
| Email routing & orchestration | TypeScript | Business logic, flexibility |
| Delivery queue & retry | TypeScript | State management, persistence |
| Template rendering | TypeScript | String interpolation |
2025-10-24 08:09:29 +00:00
2026-02-10 16:25:55 +00:00
## Project Structure
2025-10-24 08:09:29 +00:00
2026-02-10 16:25:55 +00:00
```
smartmta/
2026-02-10 22:04:56 +00:00
├── ts/ # TypeScript source
2026-02-10 16:25:55 +00:00
│ ├── mail/
2026-02-10 22:04:56 +00:00
│ │ ├── core/ # Email, EmailValidator, BounceManager, TemplateManager
│ │ ├── delivery/ # DeliverySystem, Queue, RateLimiter
│ │ │ ├── smtpclient/ # SMTP client with connection pooling
│ │ │ └── smtpserver/ # Legacy TS SMTP server (socket-handler fallback)
│ │ ├── routing/ # UnifiedEmailServer, EmailRouter, DomainRegistry, DnsManager
│ │ └── security/ # DKIMCreator, DKIMVerifier, SpfVerifier, DmarcVerifier
│ └── security/ # ContentScanner, IPReputationChecker, RustSecurityBridge
├── rust/ # Rust workspace
│ └── crates/
│ ├── mailer-core/ # Email types, validation, MIME, bounce detection
│ ├── mailer-security/ # DKIM, SPF, DMARC, IP reputation, content scanning
│ ├── mailer-smtp/ # Full SMTP server (TCP/TLS, state machine, rate limiting)
│ ├── mailer-bin/ # CLI + smartrust IPC bridge
│ └── mailer-napi/ # N-API addon (planned)
├── test/ # Test suite
├── dist_ts/ # Compiled TypeScript output
└── dist_rust/ # Compiled Rust binaries
2026-02-10 16:25:55 +00:00
```
2025-10-24 08:09:29 +00:00
2026-02-10 16:25:55 +00:00
## License and Legal Information
2025-10-24 08:09:29 +00:00
2026-02-10 16:25:55 +00:00
This repository contains open-source code licensed under the MIT License. A copy of the license can be found in the [LICENSE ](./LICENSE ) file.
2025-10-24 08:09:29 +00:00
2026-02-10 16:25:55 +00:00
**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.
2025-10-24 08:09:29 +00:00
2026-02-10 16:25:55 +00:00
### Trademarks
2025-10-24 08:09:29 +00:00
2026-02-10 16:25:55 +00:00
This project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH or third parties, and are not included within the scope of the MIT license granted herein.
2025-10-24 08:09:29 +00:00
2026-02-10 16:25:55 +00:00
Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines or the guidelines of the respective third-party owners, and any usage must be approved in writing. Third-party trademarks used herein are the property of their respective owners and used only in a descriptive manner, e.g. for an implementation of an API or similar.
2025-10-24 08:09:29 +00:00
2026-02-10 16:25:55 +00:00
### Company Information
2025-10-24 08:09:29 +00:00
2026-02-10 16:25:55 +00:00
Task Venture Capital GmbH
Registered at District Court Bremen HRB 35230 HB, Germany
2025-10-24 08:09:29 +00:00
2026-02-10 16:25:55 +00:00
For any legal inquiries or further information, please contact us via email at hello@task .vc.
2025-10-24 08:09:29 +00:00
2026-02-10 16:25:55 +00:00
By using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.