How to send emails with Remix

In Remix, `action`s run on the server — the right place for Publiq. Send when a form is submitted.

Install the SDK (npm install publiq) and set PUBLIQ_API_KEY in your server environment. The code below runs on the server — the API key never reaches the client.

import type { ActionFunctionArgs } from '@remix-run/node';
import { Publiq } from 'publiq';

const publiq = new Publiq(process.env.PUBLIQ_API_KEY);

export async function action({ request }: ActionFunctionArgs) {
  const form = await request.formData();
  await publiq.emails.send({
    from: 'you@yourdomain.com',
    to: String(form.get('email')),
    templateKey: 'welcome-email',
  });
  return { ok: true };
}

Best 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 templateKey over 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.

See also

How to send emails with Remix — Publiq Docs