LogoZonai

Custom Templates

Creating and sending your own email templates.

Creating a Template#

zonai db email template create order_confirmation

This creates <emailTemplatesPath>/order_confirmation.html pre-filled with the verify_email template as a starting point. Edit the file to fit your design.

Template Format#

Templates are plain HTML with Mustache interpolation. Include CSS inline — many email clients do not support <style> blocks.

<!DOCTYPE html>
<html>
  <body>
    <h1>Order Confirmed</h1>
    <p>Hi ,</p>
    <p>Your order <strong>#</strong> has been confirmed.</p>
    <p>Total: </p>
  </body>
</html>

Templates use Mustache syntax.

Sending a Custom Template#

Use email.send(Email(...)) from any extension hook or cron job:

@override
Future<void> afterCreateSuccess(Order order, Jwt? jwt) async {
  final customer = await get.one(
    tableName: 'users',
    where: Eq('id', order.userId.value),
  );

  if (customer == null) return;

  email.send(Email(
    to: EmailAddress(address: customer['email'] as String),
    subject: 'Order #${order.id} confirmed',
    template: 'order_confirmation',
    variables: {
      'customerName': customer['name'],
      'orderId': order.id.value,
      'total': order.total,
    },
  ));
}

The template field is the filename without .html.

Live Reloading#

Templates are read from disk at send time. Changes take effect immediately — no recompile or server restart needed.