Send email using the Lettermint Nuxt module with full TypeScript support and SSR capabilities.
npm install nuxt-lettermint # or pnpm add nuxt-lettermint # or yarn add nuxt-lettermint
nuxt.config.ts
export default defineNuxtConfig({ modules: ['nuxt-lettermint'] })
.env
NUXT_LETTERMINT_API_KEY=your-lettermint-api-key
useLettermint
<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/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 })
<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>
// 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>' }) })
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>' })
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>' })
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>' })
// 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 }] }) })