Better Auth + Shootmail : Send custom emails on authentication events
Published : 2025-04-24
subhendu singh


Table of Contents
- What is Better Auth?
- Why are emails needed with Better Auth?
- Setup Shootmail
- Grab Shootmail API key
- Install Shootmail SDK
- Initialize Shootmail client
- Setup Better Auth
- Use Shootmail to send emails at different authentication event
- Signup confirmation email
- Send magic link email
- Send OTP email - 2FA
- Send reset password email
- Send email change confirmation email
- Send invitation to organization email
- Send email change confirmation email
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
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
Setup Shootmail
I will go through the step by step process here. You can always refer the docs.Grab Shootmail API key

Install Shootmail SDK
Install the Shootmail SDK using npm or pnpmInitialize 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:- Login to you Shootmail dashboard
- 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.
