Email Metadata
Attach custom metadata to your emails for tracking, filtering, and analytics.
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 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"
}
}
}
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.
| Feature | Metadata | Tags |
|---|
| Structure | Key-value pairs | Array of strings |
| Values | Strings, numbers, booleans | Strings only |
| Query support | Query by specific values | Filter by tag presence |
| Best for | Detailed tracking data | Categorization |
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
| Limit | Value |
|---|
| Max keys | 50 |
| Max key length | 40 characters |
| Max value length | 500 characters |
| Max total size | 8 KB |
Don’t store sensitive information (passwords, API keys, PII) in metadata. Metadata is visible in the dashboard and webhook payloads.