Skip to content
Writing
DenoTypeScriptDevToolsRuntime

Deno 2.0 Transactional Email Guide: Native TypeScript Runtime

Deno 2.0 simplifies backend development with native TypeScript support and zero package.json bloat. Learn how to send transactional emails cleanly.

Deno 2.0 Architectural Paradigm: Native TypeScript & Node Compatibility

Deno 2.0 represents a major evolutionary step for server-side JavaScript and TypeScript. With native TypeScript execution out of the box, zero build steps, full npm package compatibility, and backward compatibility with standard Node APIs, it eliminates thousands of lines of configuration files.

Crucially, Deno 2.0 includes built-in web standards: the Fetch API, Streams, and Web Crypto are first-class globals. You do not need third-party SDKs or legacy SMTP drivers to build high-throughput email microservices.

1. Production Deno 2.0 HTTP Server (server.ts)

Using the high-performance Deno.serve runtime API, you can construct an ultra-fast email dispatch worker in under 35 lines of code.

TYPESCRIPT
interface EmailRequest {
  to: string;
  subject: string;
  message: string;
}

Deno.serve({ port: 8000 }, async (req: Request) => {
  if (req.method !== 'POST') {
    return new Response(JSON.stringify({ error: 'Method not allowed' }), {
      status: 405,
      headers: { 'Content-Type': 'application/json' },
    });
  }

  try {
    const payload: EmailRequest = await req.json();
    const apiKey = Deno.env.get('SADASEND_API_KEY');

    if (!apiKey) {
      return new Response(JSON.stringify({ error: 'SADASEND_API_KEY unset' }), { status: 500 });
    }

    const res = await fetch('https://api.sadasend.com/emails', {
      method: 'POST',
      headers: {
        Authorization: `Bearer ${apiKey}`,
        'Content-Type': 'application/json',
      },
      body: JSON.stringify({
        to: payload.to,
        subject: payload.subject,
        text: payload.message,
      }),
    });

    const data = await res.json();
    return new Response(JSON.stringify(data), {
      status: res.status,
      headers: { 'Content-Type': 'application/json' },
    });
  } catch (err) {
    return new Response(JSON.stringify({ error: (err as Error).message }), { status: 400 });
  }
});

2. Fine-Grained Security Permissions in Deno 2.0

Unlike Node.js where any third-party dependency can access your disk or open outbound network sockets, Deno enforces sandboxed runtime permissions. When running your service, grant access only to SadaSend API domain and required environment variables.

BASH
# Restrict network access exclusively to SadaSend Anycast API and local port
deno run --allow-net=api.sadasend.com,0.0.0.0:8000 --allow-env=SADASEND_API_KEY server.ts
Free plan

Building AI agents that send email?

Scoped API keys, per-key recipient allowlists, approval mode and a hosted MCP server with ten tools — on the free plan, without a card.