> ## Documentation Index
> Fetch the complete documentation index at: https://docs.shootmail.app/llms.txt
> Use this file to discover all available pages before exploring further.

# Better Auth

> Integrating Shootmail templates to send emails with better auth on authentication events like sign up, sign in, password reset, etc

Read this guide for more details on setting up [Shootmail with Better Auth](https://shootmail.app/blog/shootmail-better-auth-send-custom-email-on-authentication-events)

## 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](/v2/sdk)

## Setup Better Auth

Refer [Better Auth documentation](https://www.better-auth.com/docs/installation) 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](/v2/editor#cloning-pre-built-templates) 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:

```json theme={null}
{
    toEmail: string,
    templateId: string,
    subject?: string,
    provider?: string,
    preHeader?: string,
    from?: {
        name?: string,
        email: string
    }
}
```

<ParamField path="toEmail" type="string" required>
  The email address of the recipient
</ParamField>

<ParamField path="templateId" type="string" required>
  The template ID of the email template you generated by cloning pre-built better auth templates
</ParamField>

<ParamField path="subject" type="string">
  The subject of the email, if skipped, a default subject will be used (optional)
</ParamField>

<ParamField path="preHeader" type="string">
  The pre-header of the email, if skipped, a default pre-header will be used (optional)
</ParamField>

<ParamField path="provider" type="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.
</ParamField>

<ParamField path="from" type="Object">
  The sender of the email (optional)
</ParamField>

<ParamField path="from.name" type="string">
  The name of the sender (optional)
</ParamField>

<ParamField path="from.email" type="string" required>
  The email address of the sender
</ParamField>

## Methods

### Signup verification email

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

All the [common params](#common-params-for-all-the-email-methods) like `subject`, `preHeader`, `provider`, `from` are available to use. Below is the
required params for this method.

<ParamField path="verificationUrl" type="string" required>
  The verification URL
</ParamField>

### OTP verification email

```typescript theme={null}
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](#common-params-for-all-the-email-methods) like `subject`, `preHeader`, `provider`, `from` are available to use with this method.
Below is the required params for this method.

<ParamField path="otp" type="string" required>
  The OTP
</ParamField>

<ParamField path="type" type="string" required>
  The type of OTP "sign-in" | "email-verification" | "forget-password"
</ParamField>

<ParamField path="validityInMinutes" type="number">
  The validity of OTP in minutes. This is just to display a message to the user in the email.
</ParamField>

### Password reset email

```typescript theme={null}
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](#common-params-for-all-the-email-methods) like `subject`, `preHeader`, `provider`, `from` are available to use with this method.
Below is the required params for this method.

<ParamField path="resetPasswordUrl" type="string" required>
  The reset password URL
</ParamField>

### Change email verification email

```typescript theme={null}
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](#common-params-for-all-the-email-methods) like `subject`, `preHeader`, `provider`, `from` are available to use with this method.
Below is the required params for this method.

<ParamField path="verificationUrl" type="string" required>
  The verification URL
</ParamField>

<ParamField path="newEmail" type="string" required>
  The new email
</ParamField>

### Delete account verification email

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

All the [common params](#common-params-for-all-the-email-methods) like `subject`, `preHeader`, `provider`, `from` are available to use with this method.
Below is the required params for this method.

<ParamField path="verificationUrl" type="string" required>
  The verification URL
</ParamField>

### Invite organization member

```typescript theme={null}
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](#common-params-for-all-the-email-methods) like `subject`, `preHeader`, `provider`, `from` are available to use with this method.
Below is the required params for this method.

<ParamField path="inviteUrl" type="string" required>
  The invite URL
</ParamField>

<ParamField path="teamName" type="string" required>
  The team name
</ParamField>

<ParamField path="invitedByEmail" type="string" required>
  The email of the inviter
</ParamField>

<ParamField path="invitedByUsername" type="string" required>
  The name of the inviter
</ParamField>
