BuouNext
  • Features
  • DocumentsNew
  • BrutalUINew
  • ShowcaseHot
  • Pricing
  • Blog

    Getting Started

    Introduction

    BuouNext Instruction

    InstallationRun BuouNextProject StructureComponentsAuthenticationEmailAPI CallsDatabasePaymentSEO OptimizationHeadless CMSContact

    AI Instruction

    AI ImageNewAI ChatbotNewAI SearchNewAI NotionNew

    Components

    Super ClockNewFloating DockNewAI Image CompareNewAvatar ListNewClockNewDarkModeNewStepperNewRotation AvatarNewButton with TrailNewDotNewGridNewCounter CardNewMarquee CardNewProfile CardNewBento gridNewBorder Trail CardNewBuouNext FeaturesNewColor CardNewMouse FollowingNewColor GridNewAnimotion In View CardNewLevitate CardNewReorder CardNewGenerate TextNewSmooth Fliping NumberNewSmooth Fliping TextNewSmooth Typing TextNewTyping TextNewWindow Typing TextNewFade In OutNewText DropNewScalingNew
    Docs
    Email

    Email

    Learn how to configure and use resend/SMTP to send emails in the BuouNext project. This guide covers setting up email services, managing email templates, and ensuring reliable email delivery for notifications, verifications, and other communication needs.

    Sending Emails with Resend

    This guide will walk you through integrating the Resend email service to send emails from your Next.js project.

    Prerequisites

    Ensure you have a Resend account and an API key.

    Set Up API Key

    Add your Resend API key to your environment variables by adding it to the .env.local file:

    RESEND_API_KEY=your_resend_api_key

    Verify the from Address

    You need to verify your sender email address in Resend before you can send emails:

    Log in to Resend. Go to the Email Addresses or Domains section. Add and verify the email address you want to use as the from address. Resend will send a verification email to this address — follow the instructions in the email to complete the process.

    Send Email

    Now, you can use resend to send an email. Note: /api/resend is protected and should be called server-side with an internal token header.

    const response = await fetch('/api/resend', {
        method: 'POST',
        headers: {
          'Content-Type': 'application/json',
          'x-internal-token': process.env.NEXTAUTH_SECRET,
        },
        body: JSON.stringify({
          to: 'recipient@example.com',
          subject: 'Hello from Next.js and Resend',
          text: 'This is a test email from Resend!',
        }),
      });
     
      const result = await response.json();
      if (result.success) {
        console.log('Email sent successfully:', result.email);
      } else {
        console.error('Failed to send email:', result.error);
      }
     

    Sending Emails with SMTP

    Prerequisites

    Ensure you have a STMP server

    Config Transporter

    You can see this in ‘api/email/route.ts’

        const transporter = nodemailer.createTransport({
          host: process.env.EMAIL_SERVER_HOST,
          port: Number(process.env.EMAIL_SERVER_PORT),
          secure: Number(process.env.EMAIL_SERVER_PORT) === 465,
          auth: {
            user: process.env.EMAIL_SERVER_USER,
            pass: process.env.EMAIL_SERVER_PASSWORD,
          },
        })
     

    Send Email

    Now, you can use STMP to send an email.

          await fetch("/api/email", {
              method: "POST",
              headers: {
                "Content-Type": "application/json",
              },
              body: JSON.stringify({
                to: toArray,
                title: "Welcome to BuouNext",
                content: `content`,
                head: "BuouNext",
              }),
            })
     
    AuthenticationAPI Calls