AI Template Generator

Generate production-ready, mobile-responsive HTML email templates from a simple natural language prompt. Works out of the box with a built-in rule-based engine, and optionally leverages OpenAI or Anthropic for fully custom results.

  • Tables-based layout with inline CSS for email client compatibility
  • Mobile-responsive design out of the box
  • Handlebars variable support for dynamic content
  • HTML and plain text versions generated together
  • Built-in templates for welcome, newsletter, notification, receipt, password-reset, and promotional emails
  • Optional AI-powered generation via OpenAI or Anthropic

Generate a Template

POST /v1/templates/generate

Describe the email you want and receive a complete HTML template, plain text version, subject line, and metadata:

generate.ts
import { VeilMail } from '@resonia/veilmail-sdk';

const client = new VeilMail('veil_live_xxxxx');

const result = await client.templates.generate({
  prompt: 'Create a welcome email for a SaaS product called Acme',
  tone: 'friendly',
  style: 'modern',
  variables: ['firstName', 'companyName'],
});

console.log(result.subject);            // 'Welcome to {{companyName}}!'
console.log(result.metadata.type);      // 'welcome'
console.log(result.metadata.variables); // ['firstName', 'companyName', ...]
console.log(result.html);              // Full HTML email
console.log(result.text);              // Plain text version

Response Format

response.json
{
  "html": "<!DOCTYPE html>...",
  "text": "Welcome to {{companyName}}!\n\nHi {{firstName}}!...",
  "subject": "Welcome to {{companyName}}!",
  "metadata": {
    "type": "welcome",
    "variables": [
      "firstName",
      "companyName",
      "companyAddress",
      "unsubscribeUrl",
      "dashboardUrl"
    ]
  }
}

Tone Options

ToneGreeting StyleBest For
professional"Dear {{firstName}},"B2B, enterprise, formal communications
casual"Hey {{firstName}},"Startups, consumer apps, community
friendly"Hi {{firstName}}!"SaaS onboarding, newsletters, updates

Style Options

StyleDescription
minimalClean black and white design with subtle borders. No background color.
modernBlue accent colour on a light slate background. Default choice.
colorfulIndigo primary with amber accents on a soft purple background.

Template Types

The generator automatically detects the template type from your prompt, or you can specify it explicitly with the type parameter:

TypeAuto-detected Keywords
welcomewelcome, onboard
newsletternewsletter, digest
notificationnotification, alert, update
receiptreceipt, invoice, payment
password-resetpassword, reset
promotionalpromo, sale, discount, offer

Template Variables

Generated templates use Handlebars-style {{variable}} placeholders. You can request specific variables in the variables parameter, and the generator will include additional contextual variables automatically (like {{unsubscribeUrl}} and {{companyAddress}}).

variables.ts
const result = await client.templates.generate({
  prompt: 'Password reset email',
  variables: ['firstName', 'resetUrl'],
  type: 'password-reset',
});

// result.metadata.variables includes:
// ['firstName', 'resetUrl', 'companyName', 'companyAddress',
//  'unsubscribeUrl', 'subject', 'expiryMinutes']

Generate and Save

POST /v1/templates/generate-and-save

Generate a template and save it to your template library in a single API call. Requires an additional name parameter:

generate-and-save.ts
const template = await client.templates.generateAndSave({
  prompt: 'Monthly product newsletter with 3 article sections',
  name: 'Monthly Newsletter',
  tone: 'professional',
  style: 'colorful',
});

console.log(template.id);      // 'template_xxxxxxx'
console.log(template.name);    // 'Monthly Newsletter'
console.log(template.subject); // Generated subject line
console.log(template.html);    // Full HTML email

// Use it to send an email
await client.emails.send({
  from: 'news@example.com',
  to: 'subscriber@example.com',
  templateId: template.id,
  templateData: {
    firstName: 'Alice',
    articleTitle1: 'Our Biggest Launch Yet',
    articleSnippet1: 'This month we shipped...',
    articleUrl1: 'https://example.com/blog/launch',
    // ...
  },
});

AI Provider Configuration

By default, the template generator uses a built-in rule-based engine that produces well-designed HTML emails for common template types. For fully custom AI-generated templates, configure an AI provider on the server:

.env
# .env - Server-side configuration

# Option 1: OpenAI
AI_PROVIDER=openai
AI_API_KEY=sk-...

# Option 2: Anthropic
AI_PROVIDER=anthropic
AI_API_KEY=sk-ant-...

When an AI provider is configured, the generator sends the prompt to the LLM with instructions to produce email-client-compatible HTML. If the AI call fails, it automatically falls back to the rule-based generator.

Rule-based vs AI Generation

FeatureRule-based (default)AI-powered
SetupNone requiredAPI key needed
SpeedInstant (<50ms)2-10 seconds
Template types6 pre-built typesUnlimited
CustomisationTone, style, variablesFull natural language
CostFreeProvider API costs

Rate Limits

Template generation endpoints are subject to the standard API rate limit of 100 requests/minute. When using an AI provider, generation may take several seconds. The rule-based fallback is near-instant.

SDK Support

AI template generation is available in the Node.js SDK via client.templates.generate() and client.templates.generateAndSave(). For other languages, use the REST API endpoints directly.