new·The score now tells you which way it movedA brain's exam only ever grows: its own material writes questions, and so does every question a real caller asked and did not get answered. The score is a percentage over that growing set, so a brain that learned more could post a smaller number — and this week three did. One of them answered two MORE questions than the week before and showed eighteen points less. Printed as a single percentage, that reads as decline to a reader and as punishment to anyone who contributes material.all news →
mozg.beta
Sign in

Better Auth · Authentication · all subjects

email service

22 notes, read out of this brain and free to use. Each one was extracted from a source and is re-checked against its exam.

two-factor template variables

The two-factor template accepts otpCode (required), userEmail (required), userName (optional), appName (optional), and expirationMinutes (optional).

magic-link template variables

The magic-link template accepts magicLink (required), userEmail (required), appName (optional), and expirationMinutes (optional).

Email service package and imports

The email service is included in the @better-auth/infra package. Import sendEmail and createEmailSender from @better-auth/infra.

sendEmail function usage

sendEmail takes an object with template, to, and variables properties. Example: await sendEmail({ template: 'verify-email', to: 'user@example.com', variables: { verificationUrl: 'https://yourapp.com/verify?token=abc123', userEmail: 'user@example.com', userName: 'John', appName: 'Your App' } }).

createEmailSender for reusable email sending

createEmailSender creates a reusable sender object configured with apiKey and apiUrl. It is called with an object containing process.env.BETTER_AUTH_API_KEY and process.env.BETTER_AUTH_API_URL. The returned emailSender has a send method that works like sendEmail.

verify-email template variables

The verify-email template accepts verificationUrl (required), userEmail (required), verificationCode (optional, for code-based verification), userName (optional), appName (optional), and expirationMinutes (optional).

reset-password template variables

The reset-password template accepts resetLink (required), userEmail (required), userName (optional), appName (optional), and expirationMinutes (optional).

change-email template variables

The change-email template accepts confirmationLink (required), newEmail (required), currentEmail (required), userName (optional), appName (optional), and expirationMinutes (optional).

sign-in-otp template variables

The sign-in-otp template accepts otpCode (required), userEmail (required), appName (optional), and expirationMinutes (optional).

verify-email-otp template variables

The verify-email-otp template accepts otpCode (required), userEmail (required), appName (optional), and expirationMinutes (optional).

reset-password-otp template variables

The reset-password-otp template accepts otpCode (required), userEmail (required), appName (optional), and expirationMinutes (optional).

application-invite template variables

The application-invite template accepts inviteLink (required), inviterName (required), inviterEmail (required), inviteeEmail (required), appName (optional), and expirationDays (optional).

delete-account template variables

The delete-account template accepts deletionLink (required), userEmail (required), userName (optional), appName (optional), and expirationMinutes (optional).

stale-account-admin template variables

The stale-account-admin template accepts userEmail (required), userId (required), adminEmail (required), daysSinceLastActive (required), loginTime (required), userName (optional), appName (optional), loginLocation (optional), loginDevice (optional), and loginIp (optional).

EmailConfig interface

EmailConfig interface has two properties: apiKey (optional string, the Better Auth Infrastructure API key) and apiUrl (optional string, custom API URL).

Email service environment variables

The email service automatically reads from environment variables: BETTER_AUTH_API_KEY (your API key) and BETTER_AUTH_API_URL (optional, defaults to https://api.betterauth.com).

SendEmailResult interface

SendEmailResult interface has three properties: success (boolean), messageId (optional string, the email provider message ID), and error (optional string, error message if failed).

Email service plan requirements

Transactional email is available on Pro plans and above. It is not available on the Starter plan.

Email service security: avoid awaiting in production

Avoid awaiting the email sending in production to prevent timing attacks. On serverless platforms, use waitUntil or similar to ensure the email is sent without blocking the response.

Integration with Better Auth emailAndPassword flow

The email service integrates with Better Auth's emailAndPassword authentication. Pass an async sendResetPassword callback to emailAndPassword.sendResetPassword that receives user and url parameters and can call sendEmail with the reset-password template.

Integration with Better Auth emailVerification flow

The email service integrates with Better Auth's emailVerification. Pass an async sendVerificationEmail callback to emailVerification.sendVerificationEmail that receives user and url parameters and can call sendEmail with the verify-email template.

Integration with organization plugin for invitations

The organization plugin accepts a sendInvitationEmail callback that receives data with id, email, inviter, organization, and role properties. The callback can construct an invite link and send an invitation email using sendEmail.

Give your agent this brain