<script setup>const { send, sending, error, lastMessageId } = useLettermint()const sendEmail = async () => { const result = await send({ from: '[email protected]', to: '[email protected]', subject: 'Test Email from Nuxt Lettermint Module', text: 'This is a test email sent from the Nuxt Lettermint module.', html: '<h1>Test Email</h1><p>This is a <strong>test email</strong> sent from the Nuxt Lettermint module.</p>', tags: ['nuxt'] }) if (result.success) { console.log('Email sent!', lastMessageId.value) }}</script>
Send emails directly from your server routes using the sendEmail function:
Basic server email
With text and HTML
Fluent API
// server/api/send.post.tsimport { sendEmail } from '#imports'export default defineEventHandler(async () => { try { 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 } } catch (error) { return { success: false, error: (error as Error).message } }})
// server/api/send-email.post.tsimport { sendEmail } from '#imports'export default defineEventHandler(async () => { const result = await sendEmail({ from: '[email protected]', to: '[email protected]', subject: 'Server-side Email from Nuxt Lettermint', text: 'This email was sent directly from the server using the Lettermint SDK.', html: '<h2>Server-side Email</h2><p>This email was sent directly from the server using the <strong>Lettermint SDK</strong>.</p>', tags: ['nuxt'] }) return { success: true, messageId: result.message_id, status: result.status }})