All Blogs

Better Auth + Shootmail : Send custom emails on authentication events

Published : 2025-04-24
subhendu singh subhendu singh

Table of Contents

What is Better Auth?

According to the Better Auth docs, it is a framework agnostic authentication and authorization framework for typescript. It has multiple options for authentication like:
  • Email & password
  • Social sign-on
  • SSO, etc
It also has a plugin ecosystem that allows you to extend your authentication with features like 2FA, organizations, RBAC etc.

Why are emails needed with Better Auth?

Emails are needed with better auth to notify your users during various stages of authentication and authorization. For example:
  • Send email to confirm signup email
  • Send magic link email for sign in
  • Send reset password email with a link to reset password
  • Send one time passwords (OTP) on mail
  • Invite a new member to organization via email
While Better Auth provides you a simple to use typescript SDK to quickly roll your own auth with all the features, it doesn’t yet have an inbuilt solution to send emails.This is where Shootmail comes in. You can plug Shootmail’s SDK with Better Auth, that automatically sends emails to your users at different events. These emails are already designed to look beautiful and are highly compatible with major email clients, even in dark mode.Let’s jump straight into how to configure Shootmail and Better Auth together.

Setup Shootmail

I will go through the step by step process here. You can always refer the docs.

Grab Shootmail API key

You can signup on Shootmail using this registration link. One you have signed up, go to API Keys and generate a new api key.

Install Shootmail SDK

Install the Shootmail SDK using npm or pnpm

Initialize Shootmail client

In a separate file shootmail.ts, initialize and configure Shootmail SDK client.Here is a list of all the supported providers you can use. In the above code, do not forget to replace:
  • From email
  • Shootmail API Key
  • Provider information

Setup Better Auth

Install better auth SDK and setup the database, here is the documentation to get started.

Use Shootmail to send emails at different authentication event

In all these email calls, you will use the shootmail client configured previously in shootmail.ts. Let us pre-configure all our email template IDs in an enum to make it easy for us to reference themPlease note, these are default email templates IDs and are not recommended to user in production. Instead, you should create your own simply by cloning these default email templates in the Shootmail dashboard. Here is how to do this:
  • Go to purchased templates section
  • Search for better auth
  • Click on the template you want to use and clone it. This will generate a new ID for that template. Copy this ID to use later.

Signup confirmation email

MethodUsageImplementationRequired better auth magic link plugin MethodUsageImplementation

Send OTP email - 2FA

Required better auth two factor pluginMethodUsageImplementation

Send reset password email

MethodUsageImplementation

Send email change confirmation email

MethodUsageImplementation

Send invitation to organization email

Requires better auth organization pluginMethodUsageImplementation

Send email change confirmation email

MethodUsageImplementationThat’s it. Just like that, you can start sending beautiful emails with Better Auth using Shootmail. All the email templates are customizable and you can add other sections to these emails like customer feedback link, CTA to your website, support handles, social media links etc.If you are using Supabase auth, there is a guide for that too. Here is the link.Want to know more about Shootmail, visit the website and check the docs.If you have questions, feel free to shoot a DM to me on Twitter.