Templates API

Create and manage reusable email templates with variable substitution. Templates make it easy to maintain consistent email designs and content across your campaigns.

Create Template

create-template.tsTypeScript
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import Metigan from 'metigan';

const metigan = new Metigan({
  apiKey: 'your_api_key'
});

// Create a reusable email template
const template = await metigan.templates.create({
  name: 'Welcome Email Template',
  subject: 'Welcome to Our Service, {{firstName}}!',
  content: `
    <!DOCTYPE html>
    <html>
      <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
      </head>
      <body style="font-family: Arial, sans-serif; padding: 20px;">
        <h1>Welcome, {{firstName}}!</h1>
        <p>Thank you for signing up, {{firstName}} {{lastName}}.</p>
        <p>Your email address is: <strong>{{email}}</strong></p>
        
        <div style="margin-top: 30px; padding: 20px; background-color: #f3f4f6;">
          <p>To get started, please click the button below:</p>
          <a href="{{activationLink}}" 
             style="display: inline-block; padding: 12px 24px; background-color: #2563eb; 
                    color: white; text-decoration: none; border-radius: 6px;">
            Activate Account
          </a>
        </div>
      </body>
    </html>
  `
});

console.log('Template created with ID:', template.id);

Use Template

Send emails using a template ID. Learn more in the Email API documentation.

use-template.tsTypeScript
1
2
3
4
5
6
7
// Send email using a template
const result = await metigan.email.sendEmail({
  from: 'sender@example.com',
  recipients: ['recipient@example.com'],
  templateId: 'template_123', // Use the template ID
  subject: 'Welcome!' // Optional: override template subject
});
Template Variables

Templates support variables using {{variableName}} syntax. These variables are replaced when sending emails. See the Email API for details.