Skip to content

Send Emails in Nuxt with Plunk or Resend

Send transactional emails from your Nuxt app with Plunk or Resend, build templates with Nuxt Email Renderer and use the useEmail() helpers on the server.

Nuxt Starter Kit includes a simple Nuxt layer that allows you to send emails using Plunk or Resend. This layer is located in apps/web/layers/emails and is responsible for managing the email connection, sending emails, and handling errors.

Nuxt Email Renderer

I use Nuxt Email Renderer which provides a collection of high-quality, unstyled components for creating emails using Vue and TypeScript. The pre-defined templates are located in apps/web/layers/emails/app/emails/. You can use these templates to create your own emails or modify them to fit your needs.

Any layer can bring its own templates in an app/emails/ folder. The waitlist layer, for example, has WaitlistConfirmation.vue.

Sending Emails

On the server, useEmail() has helpers for the built-in emails (sendVerificationEmail, sendPasswordResetEmail, sendContactSubmissionEmail) and sendTemplate() for any other template:

await useEmail().sendTemplate({
  props: { name: user.name },
  subject: 'Welcome!',
  template: 'Welcome', // a component in any app/emails/ folder
  to: user.email,
})

In development, emails are only logged unless you set NUXT_PRIVATE_EMAIL_SEND_IN_DEV_MODE=true.

Two values are required: NUXT_PRIVATE_FROM_EMAIL (sender of all emails) and NUXT_PRIVATE_EMAIL_CONTACT (receives contact form submissions).

Plunk

My recommendation is to use a self-hosted version of Plunk.

To enable Plunk, you need to set the following environment variables in apps/web/.env:

NUXT_PRIVATE_EMAIL_PROVIDER=plunk
NUXT_PRIVATE_EMAIL_PLUNK_API_URL=YOUR_API_URL
NUXT_PRIVATE_EMAIL_PLUNK_API_KEY=YOUR_API_KEY

Resend

To enable Resend as email provider, you need to set the following environment variables in apps/web/.env:

NUXT_PRIVATE_EMAIL_PROVIDER=resend
NUXT_PRIVATE_EMAIL_RESEND_API_TOKEN=YOUR_API_KEY

Other Providers

You can easily add support for other email providers by adding a new provider in apps/web/layers/emails/server/providers/ and selecting it in apps/web/layers/emails/server/utils/getEmailProvider.ts. A provider implements the EmailProvider interface. Add the new provider name to the emailProvider enum in apps/web/layers/emails/nuxt.config.ts.

Checkout useEmail which includes other email providers like SendGrid and Mailgun.