Lädt...


🔧 Sending Emails in Nuxt 3: How I Handle Emails in My SaaS Boilerplate


Nachrichtenbereich: 🔧 Programmierung
🔗 Quelle: dev.to

If you're building anything serious in Nuxt 3, you'll need to send emails.
Here's my setup that lets you switch between Resend, SendGrid, or any other provider without rewriting code.

The Setup

Basic Configuration

const generateMailer = async () => {
  const mailer = await generateMailer({
    default: "resend",
    from: {
      address: "[email protected]",
      name: "SaaS Boilerplate",
    },
    mailers: {
      resend: transports.resend({
        key: process.env.RESEND_API_KEY || "",
        baseUrl: "https://api.resend.com",
      }),
      // Easy to add more providers!
      sendgrid: transports.sendgrid({
        key: process.env.SENDGRID_API_KEY || "",
      })
    },
  });

  return mailer;
};

Email Templates with Vue Email

Here's a simple magic link email template:

<template>
  <Html>
    <Body>
      <Container>
        <Heading>Sign In to Your Account</Heading>
        <Text>Hi {{ username }},</Text>
        <Text>Click the button below to sign in:</Text>
        <Section>
          <Button :href="signInLink">Sign In</Button>
        </Section>
        <Text>
          Or copy this link: 
          <Link :href="signInLink">{{ signInLink }}</Link>
        </Text>
        <Hr />
        <Text>This link expires in 1 hour.</Text>
      </Container>
    </Body>
  </Html>
</template>
<script setup lang="ts">
import {
  Body, Button, Container, Heading,
  Html, Link, Section, Text, Hr
} from "@vue-email/components";

interface Props {
  username?: string;
  signInLink?: string;
}

withDefaults(defineProps<Props>(), {
  username: "User",
  signInLink: "https://app.example.com/sign-in",
});
</script>

Sending Emails

import MagicLinkSignIn from "~/emails/MagicLinkSignIn.vue";
const mailer = await getMailer();
await mailer.send(async (message) => {
  message
    .to(email)
    .subject("Magic Link Sign In")
    .html(
      await render(MagicLinkSignIn, {
        username: user?.name,
        signInLink: url,
      })
    );
});

Cool Features from AdonisJS Mail

AdonisJS Mail comes with tons of powerful features that we can use:

  1. Multiple Transport Support: Switch between email providers with one line of code
  2. Calendar Events: Attach calendar invites to your emails
  3. File Attachments: Easily attach files, streams, or buffers
  4. HTML/Text Templates: Support for both HTML and plain text emails

For example, attaching a calendar invite is as simple as:

message.icalEvent((calendar) => {
  calendar.createEvent({
    summary: 'Team Meeting',
    start: DateTime.local().plus({ minutes: 30 }),
    end: DateTime.local().plus({ minutes: 60 }),
  })
});

Why this works well

  • Switch providers anytime
  • Write templates in Vue
  • Easy to test
  • All the power of AdonisJS Mail in any JS backend

Try it yourself

Want to learn more about what AdonisJS Mail can do? Check out their detailed documentation.

This email setup is part of my Nuxt SaaS boilerplate.

If you're building a SaaS, check it out—it comes with type-safe APIs using tRPC, enterprise-grade RBAC (role-based access control), and production-ready features like auth, team management, and billing.

Every feature is built with the same attention to developer experience as this email system.

...

🔧 Sending Emails in Nuxt 3: How I Handle Emails in My SaaS Boilerplate


📈 83.18 Punkte
🔧 Programmierung

🔧 Building a multi-lingual web app with Nuxt 3 and Nuxt i18n


📈 30.21 Punkte
🔧 Programmierung

🔧 The easiest way to migrate from Nuxt 3 to Nuxt 4!


📈 30.21 Punkte
🔧 Programmierung

🔧 @nuxt/test-utils - The First-Class Citizen for Nuxt Unit Testing


📈 30.21 Punkte
🔧 Programmierung

🔧 Nuxt Authorization: How to Implement Team Role-Based Access Control in Nuxt 3


📈 30.21 Punkte
🔧 Programmierung

🔧 Nuxt i18n: Translate your Nuxt.js app into multiple languages


📈 30.21 Punkte
🔧 Programmierung

🔧 Migrating from Nuxt 2 to Nuxt 3: A Comprehensive Guide


📈 30.21 Punkte
🔧 Programmierung

🔧 Nuxt build vs Nuxt Generate what is the difference?


📈 30.21 Punkte
🔧 Programmierung

🔧 Introducing @nx/nuxt: Enhanced Nuxt.js Support in Nx


📈 30.21 Punkte
🔧 Programmierung

🔧 Building a multi-lingual web app with Nuxt 3 and Nuxt i18n


📈 30.21 Punkte
🔧 Programmierung

🔧 Should You Use an Open-source SaaS Boilerplate Starter or a $300+ Paid One?


📈 28.53 Punkte
🔧 Programmierung

🔧 Introducing ThrusterKit: A Boilerplate to Speed Up Your SaaS App Launch


📈 28.53 Punkte
🔧 Programmierung

🔧 🚀 Introducing ScaleNext: A Modern and Scalable Next.js Boilerplate for Your SaaS Project


📈 28.53 Punkte
🔧 Programmierung

🔧 Django SaaS Boilerplate


📈 28.53 Punkte
🔧 Programmierung

🔧 If you are planning to build yet another SaaS boilerplate to earn Internet money, please don't.


📈 28.53 Punkte
🔧 Programmierung

🔧 Next.js SaaS Boilerplate and Starter Kit - SaaSBold


📈 28.53 Punkte
🔧 Programmierung

🔧 Building a multi-tenant B2B SaaS with Vite and Tanstack Router & Query - Part 1: The boilerplate


📈 28.53 Punkte
🔧 Programmierung

🔧 How to Handle File Uploads on the Back End in Node.js and Nuxt


📈 27.07 Punkte
🔧 Programmierung

🔧 Building a Nuxt.js + Vue.js SaaS Starter: Authentication, Payments, and Supabase Made Easy


📈 25.05 Punkte
🔧 Programmierung

🕵️ QEMU Handle Backend hw/9pfs/9p-handle.c Denial of Service


📈 23.93 Punkte
🕵️ Sicherheitslücken

🕵️ QEMU Handle Backend hw/9pfs/9p-handle.c Denial of Service


📈 23.93 Punkte
🕵️ Sicherheitslücken

📰 How to Handle Retail SaaS Security on Cyber Monday


📈 21.91 Punkte
📰 IT Security Nachrichten

📰 How to Stay GDPR Compliant While Sending Cold Emails


📈 20.07 Punkte
📰 IT Security Nachrichten

📰 Spammer Faces Decades In Prison For Sending More Than 1 Million Spam Emails


📈 20.07 Punkte
📰 IT Security Nachrichten

🔧 Sending Emails in .NET Using FluentEmail


📈 20.07 Punkte
🔧 Programmierung

🕵️ Mail.ru: [v7lk.relap.io] Sending arbitrary emails to any user


📈 20.07 Punkte
🕵️ Sicherheitslücken

📰 Microsoft Outlook outage prevents users from sending, receiving emails


📈 20.07 Punkte
📰 IT Security Nachrichten

🔧 Sending Emails in NextJs via Nodemailer


📈 20.07 Punkte
🔧 Programmierung

📰 Zero-Day Warning: It's Possible to Hack iPhones Just by Sending Emails


📈 20.07 Punkte
📰 IT Security Nachrichten

🔧 Sending Emails with React Email and Next.js


📈 20.07 Punkte
🔧 Programmierung

🔧 How I ensured user authentication, by sending emails in Spring Boot


📈 20.07 Punkte
🔧 Programmierung

🔧 Sending Multilingual Emails with Postmark and Gitloc


📈 20.07 Punkte
🔧 Programmierung

matomo