GuideIntegrationsBetter Auth

    Better Auth Integration

    Connect Better Auth to Simply Send to deliver verification emails, OTP codes, and password reset links from your own custom domain.

    Overview

    Better Auth is a modern open-source authentication library for TypeScript frameworks. Since it is self-hosted, it relies on you providing an email delivery channel for its auth flows. Integrating Simply Send gives you:

    Verified Custom Domain

    Verification messages will come directly from your own domain (e.g. [email protected]).

    High Deliverability

    Avoid spam folders and ensure fast delivery for passwordless magic links and user sign-ups.

    Setup Guide

    To integrate Better Auth with Simply Send, provision SMTP credentials and add them as environment variables in your server project.

    1. 1
      Provision Credentials in Simply SendGo to the Integrations tab in your User Portal and click Connect on the Better Auth card. Choose a credential label and click Create Credentials. Copy the details.
    2. 2
      Configure Environment VariablesAdd these configuration variables to your server's environment configuration or .env file. Use the SMTP Server value shown in the Simply Send credential setup popup:
      EMAIL_SERVER_HOST=<smtp-server-from-setup>
      EMAIL_SERVER_PORT=587
      EMAIL_SERVER_USER=your-generated-username
      EMAIL_SERVER_PASSWORD=your-generated-password
      [email protected]
    3. 3
      Configure Better Auth ServerIn your authentication backend initialization file, configure `nodemailer` and hook it into the `betterAuth` configuration:
      import { betterAuth } from "better-auth";
      import nodemailer from "nodemailer";
      
      const transporter = nodemailer.createTransport({
        host: process.env.EMAIL_SERVER_HOST,
        port: Number(process.env.EMAIL_SERVER_PORT),
        auth: {
          user: process.env.EMAIL_SERVER_USER,
          pass: process.env.EMAIL_SERVER_PASSWORD,
        },
      });
      
      export const auth = betterAuth({
        emailAndPassword: {
          enabled: true,
          sendVerificationEmail: async ({ user, url }) => {
            await transporter.sendMail({
              from: process.env.EMAIL_FROM,
              to: user.email,
              subject: "Verify your email address",
              html: `<a href="${url}">Verify Email</a>`,
            });
          },
        },
      });
    4. 4
      Add Compliance Variables to Your Email HTMLSimply Send requires two compliance variables in every email HTML body. Add them to the html string inside sendVerificationEmail (and any other auth email handlers). These are replaced at send time with your configured unsubscribe link and company address from the Templates → Compliance section in Simply Send:
      <!-- Required in every email HTML -->
      <div>{{unsubscribe_email_html}}</div>
      <div>{{company_address_html}}</div>
      
      <!-- Optional -->
      <div>{{report_abuse_email_html}}</div>
      Emails missing these variables will be rejected by Simply Send with a MISSING_TEMPLATE_VARIABLES error.