Skip to content

Configuration

You can configure the module in your nuxt.config.ts under the transportMailer key or using Environment Variables.

Nuxt Config

typescript
export default defineNuxtConfig({
  modules: ['@vikeriait/nuxt-transport-mailer'],

  transportMailer: {
    // Example configuration
    driver: 'smtp',
    smtp: {
      host: 'smtp.example.com',
      port: 587,
      auth: {
        user: 'user',
        pass: 'pass',
      },
    }
  },
})

Options Reference

Main Options

OptionTypeDefaultDescription
driverstring'smtp'The transport driver to use.
defaultsobject{ from: '' }Default options applied to every email.

SMTP Options (smtp)

OptionTypeDefaultDescription
hoststring'localhost'SMTP server hostname.
portnumber2525SMTP server port.
securebooleanfalseIf true, uses TLS.
auth.userstringundefinedSMTP username.
auth.passstringundefinedSMTP password.

TIP

For a full list of SMTP options, please refer to the Nodemailer SMTP documentation.

Server API (serverApi)

OptionTypeDefaultDescription
enabledbooleanfalseEnables the /api/mail/send endpoint.
routestring'/api/mail/send'The path for the API endpoint.

Security (security)

Captcha (Custom)

OptionTypeDefaultDescription
captcha.enabledbooleanfalseEnables captcha verification.
captcha.provider'turnstile' | 'recaptcha' | 'hcaptcha'undefinedCaptcha provider.
captcha.secretKeystringundefinedSecret key for captcha provider.

Other Security Rules

The security object integrates directly with nuxt-security.

INFO

If serverApi.enabled is true, the following Rate Limiter defaults are automatically applied to the API route to prevent abuse:

typescript
rateLimiter: {
  tokensPerInterval: 2,
  interval: 3000000, // 50 minutes
}

You can override these defaults or add any other nuxt-security route rules (CORS, headers, etc.).

typescript
security: {
  rateLimiter: {
    tokensPerInterval: 5,
    interval: 300000,
  },
  corsHandler: {
    origin: '*',
    methods: ['POST']
  }
}

Note

These settings rely on the nuxt-security module.

  1. You must have nuxt-security installed for these rules (Rate Limiter, CORS, etc.) to take effect.
  2. Scoped Rules: Any rule defined under security (except captcha) is applied only to the mailer API route (e.g., /api/mail/send). It will not affect the rest of your application.
  3. Inheritance: The mailer route will also inherit any global security rules defined by nuxt-security (e.g., global Security Headers), unless you explicitly override or disable them within the security object here.

Environment Variables

The recommended way to handle sensitive credentials is using a .env file.

bash
# Driver
NUXT_TRANSPORT_MAILER_DRIVER=smtp

# SMTP
NUXT_TRANSPORT_MAILER_SMTP_HOST=smtp.example.com
NUXT_TRANSPORT_MAILER_SMTP_PORT=587
NUXT_TRANSPORT_MAILER_SMTP_AUTH_USER=myuser
NUXT_TRANSPORT_MAILER_SMTP_AUTH_PASS=mypassword
NUXT_TRANSPORT_MAILER_SMTP_SECURE=false

# Defaults
NUXT_TRANSPORT_MAILER_DEFAULTS_FROM="My App <[email protected]>"

# Security - Captcha
NUXT_TRANSPORT_MAILER_SECURITY_CAPTCHA_ENABLED=true
NUXT_TRANSPORT_MAILER_SECURITY_CAPTCHA_PROVIDER=turnstile
NUXT_TRANSPORT_MAILER_SECURITY_CAPTCHA_SECRET_KEY=...