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

# Send emails with Neon

> Send Managed Better Auth emails, sync Neon users to contacts, send emails from Neon Functions, and store email events in Neon with AutoSend.

![AutoSend x Neon](https://mintcdn.com/autosend-13920f5c/elz97IrcT4EqDdvp/images/guides/autosendxneon.jpg?fit=max\&auto=format\&n=elz97IrcT4EqDdvp\&q=85\&s=305b28a3494206bc5bd32540321c0f93)

You can use AutoSend with [Neon](https://neon.com) to:

* send [Managed Better Auth](https://neon.com/docs/auth/overview) emails, such as verification and password reset codes
* sync Managed Better Auth users to AutoSend contacts
* send transactional emails and events from Neon Functions
* store AutoSend email events in Postgres

## Set Up AutoSend

Add and verify a [sending domain](https://docs.autosend.com/domain.md) in AutoSend. You send every email on this page from an address on that domain.

## Send Managed Better Auth Emails

Choose one of two options.

> [card] [Custom SMTP](https://docs.autosend.com/guides/smtp/neon.md)
>
> The simplest option. Managed Better Auth sends its default emails from your address through AutoSend SMTP.

> [card] [Webhooks](https://neon.com/guides/neon-auth-webhooks-nextjs)
>
> Full control. Handle the `send.otp` and `send.magic_link` events and send each email with an AutoSend template.

With webhooks, Managed Better Auth sends each email as an event to your [webhook](https://neon.com/docs/auth/guides/webhooks) instead of sending the email itself. A `send.otp` event has an `otp_type` and a `send.magic_link` event has a `link_type`, each `sign-in`, `email-verification`, or `forget-password`, so you can map each one to its own AutoSend template. You can reuse the templates from the [Better Auth guide](https://docs.autosend.com/guides/better-auth.md#create-email-templates).

> [!NOTE]
>
> While a webhook subscribes to `send.otp` or `send.magic_link`, Neon sends those emails to the webhook instead of through SMTP.

## Sync Managed Better Auth Users to AutoSend Contacts

Managed Better Auth sends a `user.created` [webhook](https://neon.com/docs/auth/guides/webhooks) event after it creates a user. Your handler can:

1. Call [Upsert Contact](https://docs.autosend.com/api-reference/contacts/upsert-contact.md) with the user's email and the Managed Better Auth user ID as `userId`.
2. [Send](https://docs.autosend.com/api-reference/events/send-event.md) a `signup_completed` [event](https://docs.autosend.com/automations/events.md) that starts an onboarding [automation](https://docs.autosend.com/automations.md).

## Send Emails with Neon Functions

Send transactional emails from AutoSend templates, and send events that start automations, from a Neon Function.

> [card] [Send emails with Neon Functions](https://docs.autosend.com/guides/neon-functions.md)
>
> Add the Send email with AutoSend template with `neon functions new autosend-email`.

## Store Email Events in Neon

Point an AutoSend [webhook](https://docs.autosend.com/others/webhooks/introduction.md) at a Neon Function that stores delivery, bounce, spam, and unsubscribe events in Postgres.

> [card] [Store AutoSend webhook events in Neon](https://neon.com/guides/autosend-webhooks)
>
> Verify each webhook, store it without duplicates, and test on a branch.

> [!NOTE]
>
> Running Better Auth in your own app instead? See our [Better Auth guide](https://docs.autosend.com/guides/better-auth.md).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.