How to send emails with Deno
The Publiq SDK works in Deno via the `npm:` specifier. Run with network and env permissions.
Import straight from npm and set PUBLIQ_API_KEY in the environment:
import { Publiq } from 'npm:publiq';
const publiq = new Publiq(Deno.env.get('PUBLIQ_API_KEY'));
await publiq.emails.send({
from: 'you@yourdomain.com',
to: 'user@example.com',
templateKey: 'welcome-email',
});
// deno run --allow-net --allow-env main.tsBest practices
- Always call Publiq from the server — never expose the API key on the client.
- Create the client instance once and reuse it across requests.
- Prefer
templateKeyover inline HTML to keep content versioned. - Handle
PubliqError(status/code); the SDK already retries transient errors with backoff. - Send from a verified domain — see Domains.