1. Installation

Install the Nuxt module:
npm install nuxt-lettermint
# or
pnpm add nuxt-lettermint
# or
yarn add nuxt-lettermint
Add the module to your nuxt.config.ts:
export default defineNuxtConfig({
  modules: ['nuxt-lettermint']
})
Set your API key in .env:
NUXT_LETTERMINT_API_KEY=your-lettermint-api-key

2. Send your first email

Client-side (Composable)

Use the useLettermint composable in your Vue components:
<script setup>
const { send, sending, error, lastMessageId } = useLettermint()

async function sendWelcomeEmail() {
  const response = await send({
    from: 'John Doe <john@yourdomain.com>',
    to: 'recipient@example.com',
    subject: 'Hello from Lettermint',
    text: 'This is a test email sent using the Lettermint Nuxt module.'
  })
  
  if (response.success) {
    console.log(`Email sent with ID: ${response.messageId}`)
  }
</script>

<template>
  <button @click="sendWelcomeEmail" :disabled="sending">
    {{ sending ? 'Sending...' : 'Send Email' }}
  </button>
  <p v-if="error">{{ error }}</p>
</template>

Server-side (API Routes)

Send emails from your server API routes:
// server/api/send-welcome.post.ts
import { sendEmail } from '#imports'

export default defineEventHandler(async (event) => {
  const response = await sendEmail({
    from: 'John Doe <john@yourdomain.com>',
    to: 'recipient@example.com',
    subject: 'Welcome to our platform',
    html: '<h1>Welcome!</h1><p>Thanks for signing up.</p>',
    text: 'Welcome! Thanks for signing up.'
  })
  
  return response
})

3. Email Features

Basic Email with HTML and Text

<script setup>
const { send } = useLettermint()

async function sendEmail() {
  await send({
    from: 'John Doe <john@yourdomain.com>',
    to: 'recipient@example.com',
    subject: 'Your account is ready!',
    html: '<h1>Welcome!</h1><p>Thanks for signing up.</p>',
    text: 'Welcome! Thanks for signing up.'
  })
}
</script>

Multiple Recipients

Send to multiple recipients using CC and BCC:
// server/api/newsletter.post.ts
import { sendEmail } from '#imports'

export default defineEventHandler(async () => {
  return await sendEmail({
    from: 'John Doe <john@yourdomain.com>',
    to: ['user1@example.com', 'user2@example.com'],
    cc: 'manager@yourdomain.com',
    bcc: 'archive@yourdomain.com',
    subject: 'Monthly Newsletter',
    html: '<h1>This Month\'s Updates</h1>'
  })
})

Custom Headers and Reply-To

Add custom headers and set reply-to addresses:
const { send } = useLettermint()

await send({
  from: 'support@yourdomain.com',
  to: 'customer@example.com',
  replyTo: 'help@yourdomain.com',
  subject: 'Support Ticket #12345',
  headers: {
    'X-Priority': '1',
    'X-Ticket-ID': '12345'
  },
  html: '<p>Your support ticket has been updated.</p>'
})

Metadata

Add metadata for tracking and webhook payloads:
const { send } = useLettermint()

await send({
  from: 'notifications@yourdomain.com',
  to: 'user@example.com',
  subject: 'Order Confirmation',
  metadata: {
    orderId: 'ORD-12345',
    customerId: 'CUST-678',
    type: 'order_confirmation'
  },
  html: '<p>Your order has been confirmed.</p>'
})
Metadata is included in webhook payloads but not added to the actual email headers. Use it for tracking and analytics purposes.

Tags

Use a tag to categorize your emails:
const { send } = useLettermint()

await send({
  from: 'alerts@yourdomain.com',
  to: 'admin@yourdomain.com',
  subject: 'System Alert',
  tag: 'critical',
  html: '<p>Critical system alert detected.</p>'
})

File Attachments

Attach files to your emails:
// Client-side with file input
<script setup>
const { send } = useLettermint()

async function sendWithAttachment(file: File) {
  const reader = new FileReader()
  
  reader.onload = async () => {
    const base64 = reader.result?.toString().split(',')[1]
    
    await send({
      from: 'invoices@yourdomain.com',
      to: 'customer@example.com',
      subject: 'Your Invoice',
      html: '<p>Please find your invoice attached.</p>',
      attachments: [{
        filename: file.name,
        content: base64
      }]
    })
  }
  
  reader.readAsDataURL(file)
}
</script>
// Server-side with fs
import fs from 'fs'
import { sendEmail } from '#imports'

export default defineEventHandler(async () => {
  const fileContent = fs.readFileSync('/path/to/document.pdf')
  const base64Content = fileContent.toString('base64')
  
  return await sendEmail({
    from: 'invoices@yourdomain.com',
    to: 'customer@example.com',
    subject: 'Your Invoice',
    html: '<p>Please find your invoice attached.</p>',
    attachments: [{
      filename: 'invoice.pdf',
      content: base64Content
    }]
  })
})

GitHub Repository

Find the complete source code, report issues, or contribute on GitHub.