Skip to main content
Use tags and metadata to categorize, track, and organize your transactional emails.

Tags

Tags help you categorize and filter emails in your Lettermint dashboard:
import { sendEmail } from '#imports'

export default defineEventHandler(async () => {
  const result = await sendEmail({
    from: '[email protected]',
    to: '[email protected]',
    subject: 'Test Email',
    html: '<h1>Hello from sendEmail function</h1>',
    tags: ['test']
  })

  return { success: true, result }
})

Multiple tags

Add multiple tags to better organize your emails:
import { sendEmail } from '#imports'

export default defineEventHandler(async () => {
  const result = await sendEmail({
    from: '[email protected]',
    to: '[email protected]',
    subject: 'Welcome Email',
    html: '<h1>Welcome to our platform!</h1>',
    tags: ['welcome', 'onboarding', 'automated']
  })

  return { success: true, result }
})
Tags are useful for filtering and searching emails in your dashboard, as well as for analytics and reporting.

Metadata

Store custom data with your emails using the metadata field. This is useful for tracking user IDs, campaign information, or any custom data:
import { sendEmail } from '#imports'

export default defineEventHandler(async () => {
  const result = await sendEmail({
    from: '[email protected]',
    to: '[email protected]',
    subject: 'Order Confirmation',
    html: '<h1>Your order has been confirmed</h1>',
    metadata: {
      userId: '12345',
      orderId: 'ORD-789',
      orderTotal: 99.99,
      customerTier: 'premium'
    },
    tags: ['order', 'confirmation']
  })

  return { success: true, result }
})

Custom headers

Add custom email headers for advanced use cases:
import { sendEmail } from '#imports'

export default defineEventHandler(async () => {
  const result = await sendEmail({
    from: '[email protected]',
    to: '[email protected]',
    subject: 'Custom Headers Example',
    html: '<h1>Email with custom headers</h1>',
    headers: {
      'X-Custom-Header': 'custom-value',
      'X-Campaign-ID': 'summer-2024',
      'X-Priority': 'high'
    }
  })

  return { success: true, result }
})
Custom headers can be useful for email tracking, categorization, or integration with third-party services.

Complete example

Combine tags, metadata, and custom headers for comprehensive email tracking:
import { sendEmail } from '#imports'

export default defineEventHandler(async () => {
  const result = await sendEmail({
    from: '[email protected]',
    to: '[email protected]',
    cc: '[email protected]',
    bcc: '[email protected]',
    replyTo: '[email protected]',
    subject: 'Test Full Options',
    text: 'Plain text version',
    html: '<h1>HTML version</h1>',
    headers: {
      'X-Custom-Header': 'custom-value'
    },
    metadata: {
      userId: '12345',
      campaign: 'test-campaign'
    },
    tags: ['test', 'full-options'],
    attachments: [
      {
        filename: 'test.txt',
        content: 'Test attachment content'
      }
    ]
  })

  return { success: true, result }
})

Dynamic tags and metadata

Use dynamic values based on user data or application state:
import { sendEmail } from '#imports'

export default defineEventHandler(async (event) => {
  const user = await getUserFromSession(event)

  const result = await sendEmail({
    from: '[email protected]',
    to: user.email,
    subject: `Welcome ${user.name}!`,
    html: `<h1>Welcome ${user.name}!</h1>`,
    metadata: {
      userId: user.id,
      signupDate: user.createdAt,
      accountType: user.type
    },
    tags: ['welcome', user.type, 'automated']
  })

  return { success: true, result }
})

Type definition

The metadata and tags types:
interface LettermintEmailOptions {
  // ... other fields
  tags?: string[]
  metadata?: Record<string, unknown>
  headers?: Record<string, string>
}
Metadata accepts any JSON-serializable values, including strings, numbers, booleans, arrays, and nested objects.

Next steps

Basic email

Learn the basics of sending emails

API Reference

Explore the complete API reference

Build docs developers (and LLMs) love