Use tags and metadata to categorize, track, and organize your transactional emails.
Tags help you categorize and filter emails in your Lettermint dashboard:
Server-side
Client-side
Fluent API
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 }
})
<script setup>
const { send } = useLettermint()
await send({
from: '[email protected]',
to: '[email protected]',
subject: 'Test Email',
html: '<h1>Hello World</h1>',
tags: ['nuxt']
})
</script>
import { useLettermint } from '#imports'
export default defineEventHandler(async () => {
const lettermint = useLettermint()
const result = await lettermint.email
.from('[email protected]')
.to('[email protected]')
.subject('Test SDK Email')
.html('<h1>Hello from Lettermint SDK</h1>')
.tag('sdk-test')
.send()
return { success: true, result }
})
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.
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 }
})
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 }
})
Use dynamic values based on user data or application state:
User-specific
Campaign tracking
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 }
})
import { sendEmail } from '#imports'
export default defineEventHandler(async (event) => {
const campaign = await getCampaignData(event)
const result = await sendEmail({
from: '[email protected]',
to: campaign.recipients,
subject: campaign.subject,
html: campaign.template,
metadata: {
campaignId: campaign.id,
campaignName: campaign.name,
sentAt: new Date().toISOString(),
segment: campaign.segment
},
tags: ['campaign', campaign.type, campaign.segment],
headers: {
'X-Campaign-ID': campaign.id,
'X-Campaign-Type': campaign.type
}
})
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