Next.js + React Email
Build the email body with React components (react-email), render to HTML and send with Publiq.
Install @react-email/components and @react-email/render, create the component and render it on the server:
import { render } from '@react-email/render';
import { WelcomeEmail } from '@/emails/welcome';
import { Publiq } from 'publiq';
const publiq = new Publiq(process.env.PUBLIQ_API_KEY);
const html = await render(<WelcomeEmail name="Ana" />);
await publiq.emails.send({
from: 'you@yourdomain.com',
to: 'user@example.com',
subject: 'Welcome to Acme',
html,
});Or skip React: create the template in the dashboard AI builder and send it by templateKey.
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
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.