Why legacy email libraries feel sluggish in Bun
Bun has revolutionized JavaScript backends by delivering sub-millisecond cold starts, native TypeScript execution, and high-performance I/O. Yet many email tutorials still instruct developers to install nodemailer alongside dozens of legacy stream polyfills and C++ addons.
In modern cloud environments, transactional email should be dispatched over HTTP/2 using native fetch with connection pooling and zero external dependencies.
| Metric / Feature | Legacy Node + Nodemailer | Bun Native Fetch + SadaSend |
|---|---|---|
| Dependency Overhead | 24+ MB node_modules footprint | 0 external dependencies (built-in fetch) |
| Cold Start Latency | 80ms – 140ms in serverless containers | No cold start — native V8/JSC boot |
| Connection Handling | Single-socket SMTP handshakes | Pooled HTTP/2 keep-alive connections |
| Type Checking | External @types definitions required | First-class native TypeScript execution |
Method 1: Sending via Bun Native Fetch (Zero Dependencies)
Because Bun has native fetch with connection pooling, you can dispatch authenticated emails in four lines of code without installing any packages:
// send.ts — run directly with `bun send.ts`
const response = await fetch('https://api.sadasend.com/emails', {
method: 'POST',
headers: {
'Authorization': `Bearer ${process.env.SADASEND_API_KEY}`,
'Content-Type': 'application/json',
'Idempotency-Key': `otp_${crypto.randomUUID()}`,
},
body: JSON.stringify({
from: 'system@yourdomain.com',
to: 'user@example.com',
subject: 'Your authentication code',
text: 'Your code is: 482-910. Valid for 10 minutes.',
}),
});
if (!response.ok) {
const error = await response.json();
throw new Error(`Email dispatch failed: ${error.message}`);
}
const data = await response.json();
console.log('Dispatched message ID:', data.id);Method 2: Using the Type-Safe SadaSend SDK
For complex applications requiring templates, attachments, and retry logic, use the lightweight sadasend package:
import { SadaSend } from 'sadasend';
const sadasend = new SadaSend({ apiKey: process.env.SADASEND_API_KEY });
const result = await sadasend.emails.send({
from: 'notifications@yourdomain.com',
to: 'founder@startup.io',
subject: 'Weekly Infrastructure Report',
markdown: `
# Weekly Summary
All systems operational.
- **Uptime:** 99.99%
- **Delivery Latency:** 412ms
`,
});Microtask Queue Dispatching in Bun HTTP Servers
In high-throughput API handlers (such as user signup routes), you never want to block the HTTP response on an external email network request. Use Bun’s queueMicrotask for non-blocking dispatch:
import { serve } from 'bun';
serve({
port: 6000,
async fetch(req) {
if (req.method === 'POST' && new URL(req.url).pathname === '/api/signup') {
const user = await req.json();
// Background microtask dispatch — response returns immediately
queueMicrotask(async () => {
try {
await fetch('https://api.sadasend.com/emails', {
method: 'POST',
headers: {
'Authorization': `Bearer ${process.env.SADASEND_API_KEY}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
from: 'welcome@yourdomain.com',
to: user.email,
subject: 'Welcome to the platform!',
text: `Hello ${user.name}, your account is active.`,
}),
});
} catch (err) {
console.error('Background send failed:', err);
}
});
return Response.json({ status: 'user_created' }, { status: 201 });
}
return new Response('Not Found', { status: 404 });
},
});Send transactional emails in under 3 minutes
EU-hosted delivery, custom SMTP relay, 100% SPF/DKIM alignment, and automated suppression firewalls. 6,000 free sends every month without a credit card.
Building SadaSend — transactional email with an MCP server that has a ceiling. Writes about deliverability, email infrastructure, and what happens when you hand an autonomous agent a sending credential.