Skip to main content

Email Metadata

Attach custom metadata to your emails for tracking, filtering, and analytics.

Adding Metadata

await lettr.emails.send({
  from: 'you@example.com',
  to: ['recipient@example.com'],
  subject: 'Order Confirmation',
  html: '<p>Your order is confirmed!</p>',
  metadata: {
    orderId: 'order_12345',
    customerId: 'cust_67890',
    orderTotal: 99.99,
    source: 'checkout'
  }
});

Metadata in Webhooks

Metadata is included in webhook payloads:
{
  "type": "email.delivered",
  "data": {
    "emailId": "email_abc123",
    "to": "recipient@example.com",
    "metadata": {
      "orderId": "order_12345",
      "customerId": "cust_67890",
      "orderTotal": 99.99,
      "source": "checkout"
    }
  }
}

Query by Metadata

Find emails by metadata values:
const emails = await lettr.emails.list({
  metadata: {
    orderId: 'order_12345'
  }
});

Use Cases

Order Tracking

Link emails to orders for support and auditing.

User Attribution

Track which user triggered each email.

Analytics

Segment email performance by custom dimensions.

Debugging

Include request IDs for easier troubleshooting.

Metadata vs Tags

FeatureMetadataTags
StructureKey-value pairsArray of strings
ValuesStrings, numbers, booleansStrings only
Query supportQuery by specific valuesFilter by tag presence
Best forDetailed tracking dataCategorization

Example: Full Tracking Setup

await lettr.emails.send({
  from: 'orders@example.com',
  to: ['customer@example.com'],
  subject: 'Order #12345 Confirmed',
  html: orderConfirmationHtml,
  
  // Tags for categorization
  tags: ['transactional', 'order-confirmation', 'us-region'],
  
  // Metadata for detailed tracking
  metadata: {
    orderId: 'order_12345',
    customerId: 'cust_67890',
    orderTotal: 299.99,
    currency: 'USD',
    itemCount: 3,
    shippingMethod: 'express',
    requestId: 'req_xyz789'
  }
});

Limits

LimitValue
Max keys50
Max key length40 characters
Max value length500 characters
Max total size8 KB
Don’t store sensitive information (passwords, API keys, PII) in metadata. Metadata is visible in the dashboard and webhook payloads.