nuxt-lettermint
Nuxt Lettermint Module
A Nuxt module for sending emails using the Lettermint email service. This module provides a seamless integration with Lettermint's Node.js SDK for both server-side and client-side email sending capabilities.
Lettermint is a European transactional email service provider focused on simplicity, reliability, and developer experience. Visit Lettermint.co for more information about our email platform.
Features
- 🚀 Full TypeScript support
- 🔒 Secure API key management
- 📧 Simple composable for client-side usage
- 🛠️ Direct server-side SDK access
- ⚙️ Flexible configuration via environment variables or
nuxt.config.ts
- 🎯 Compatible with Nuxt 3 and Nuxt 4
Quick Setup
1. Install the module
Using the Nuxt CLI (recommended):
npx nuxi module add lettermint
Or install manually:
# npm
npm install nuxt-lettermint
# pnpm
pnpm add nuxt-lettermint
# yarn
yarn add nuxt-lettermint
2. Add to your Nuxt config
// nuxt.config.ts
export default defineNuxtConfig({
modules: ['nuxt-lettermint']
})
3. Configure your API key
First, get your API key from Lettermint:
- Go to https://dash.lettermint.co/projects
- Select your project
- Find your API token
Then set your API key in one of two ways:
Option A: Create a .env
file in your project root (recommended):
NUXT_LETTERMINT_API_KEY=your-lettermint-api-key
Option B: Add it directly to your nuxt.config.ts
:
export default defineNuxtConfig({
modules: ['nuxt-lettermint'],
lettermint: {
apiKey: 'your-api-key'
}
})
Configuration
The module accepts the following configuration options:
export default defineNuxtConfig({
modules: ['nuxt-lettermint'],
lettermint: {
// Your Lettermint API key (see step 3 above for configuration options)
apiKey: 'your-api-key',
// Enable/disable the auto-generated /api/lettermint/send endpoint (default: true)
// Set to false if you want to create your own custom endpoints
autoEndpoint: true
}
})
Disabling the Auto-Generated Endpoint
By default, the module creates an endpoint at /api/lettermint/send
for sending emails. If you prefer to create your own custom endpoints, you can disable this behavior:
// nuxt.config.ts
export default defineNuxtConfig({
modules: ['nuxt-lettermint'],
lettermint: {
autoEndpoint: false
}
})
Note: When you disable the auto-generated endpoint:
- You can still send emails directly from your server code using the
sendEmail
function - The client-side
useLettermint()
composable will not work unless you create a custom endpoint at/api/lettermint/send
- Only create a custom endpoint if you need specific routing, additional logic, or client-side email sending:
// server/api/custom-send.post.ts (optional)
import { sendEmail } from '#imports'
export default defineEventHandler(async (event) => {
const body = await readBody(event)
// Add your custom logic here
return await sendEmail(body)
})
Usage
Client-Side
<script setup>
const { send, sending, error } = useLettermint()
await send({
from: '[email protected]',
to: '[email protected]',
subject: 'Hello!',
html: '<h1>Hello World</h1>'
})
</script>
Server-Side
// server/api/send.post.ts
import { sendEmail } from '#imports'
export default defineEventHandler(async () => {
return await sendEmail({
from: '[email protected]',
to: '[email protected]',
subject: 'Welcome',
html: '<h1>Welcome!</h1>',
tags: ['welcome']
})
})
Advanced Usage
import { useLettermint } from '#imports'
const lettermint = useLettermint()
await lettermint.email
.from('[email protected]')
.to('[email protected]')
.subject('Hello')
.html('<h1>Hello</h1>')
.tag('campaign')
.send()
Links
License
MIT License © 2025 Lettermint