Read this guide for more details on setting up Shootmail with Better Auth

Setup Shootmail SDK

If you are an existing user, just update the Shootmail SDK. If you are a new user, head to the SDK setup page

Setup Better Auth

Refer Better Auth documentation to get started

Integrating Shootmail templates

Clone the pre-built better auth email templates to further customize them. These pre-built email templates already have the required parameters configured. You can add custom elements like buttons, footer, social media links etc. Guide on cloning the templates.

Cloning the template will also generate a unique template ID that you will need to send emails with better auth.

Sending emails

Common params for all the email methods:

{
    toEmail: string,
    templateId: string,
    subject?: string,
    provider?: string,
    preHeader?: string,
    from?: {
        name?: string,
        email: string
    }
}
toEmail
string
required

The email address of the recipient

templateId
string
required

The template ID of the email template you generated by cloning pre-built better auth templates

subject
string

The subject of the email, if skipped, a default subject will be used (optional)

preHeader
string

The pre-header of the email, if skipped, a default pre-header will be used (optional)

provider
string

The email provider you want to use to send the email. If you have configured only one email provider while initializing the Shootmail client, you can skip this. The only configured email provider will be used as default.

from
Object

The sender of the email (optional)

from.name
string

The name of the sender (optional)

from.email
string
required

The email address of the sender

Methods

Signup verification email

const shootmailResponse = await shootmail.betterAuth.sendVerificationEmail({
    templateId: "signup-verification-template-id",
    verificationUrl: data.url,
    toEmail: data.user.email,
});

All the common params like subject, preHeader, provider, from are available to use. Below is the required params for this method.

verificationUrl
string
required

The verification URL

OTP verification email

const shootmailResponse = await shootmail.betterAuth.sendVerificationOtp({
    templateId: "otp-verification-template-id",
    toEmail: data.user.email,
    otp: data.otp,
    type: "sign-in",
    validityInMinutes: 5
});

All the common params like subject, preHeader, provider, from are available to use with this method. Below is the required params for this method.

otp
string
required

The OTP

type
string
required

The type of OTP “sign-in” | “email-verification” | “forget-password”

validityInMinutes
number

The validity of OTP in minutes. This is just to display a message to the user in the email.

Password reset email

const shootmailResponse = await shootmail.betterAuth.sendResetPasswordEmail({
    templateId: "password-reset-template-id",
    toEmail: data.user.email,
    resetPasswordUrl: data.url,
    subject: "Reset Password",
    preHeader: "We have received a request to reset your password",
});

All the common params like subject, preHeader, provider, from are available to use with this method. Below is the required params for this method.

resetPasswordUrl
string
required

The reset password URL

Change email verification email

const shootmailResponse = await shootmail.betterAuth.sendChangeEmailVerificationEmail({
    templateId: "change-email-verification-template-id",
    toEmail: data.user.email,
    newEmail: data.newEmail,
    verificationUrl: data.url,
});

All the common params like subject, preHeader, provider, from are available to use with this method. Below is the required params for this method.

verificationUrl
string
required

The verification URL

newEmail
string
required

The new email

Delete account verification email

const shootmailResponse = await shootmail.betterAuth.sendDeleteAccountVerification({
    templateId: "delete-account-verification-template-id",
    toEmail: data.user.email,
    verificationUrl: data.url,
});

All the common params like subject, preHeader, provider, from are available to use with this method. Below is the required params for this method.

verificationUrl
string
required

The verification URL

Invite organization member

const shootmailResponse = await shootmail.betterAuth.sendOrganizationInvitation({
    templateId: "invite-organization-member-template-id",
    toEmail: data.user.email,
    invitedByEmail: data.inviter.user.email,
    invitedByUsername: data.inviter.user.name,
    teamName: data.organization.name,
    inviteUrl: data.url,
});

All the common params like subject, preHeader, provider, from are available to use with this method. Below is the required params for this method.

inviteUrl
string
required

The invite URL

teamName
string
required

The team name

invitedByEmail
string
required

The email of the inviter

invitedByUsername
string
required

The name of the inviter