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

# Send Email with Bun

> Send transactional emails using Sequenzy and Bun

# Send Email with Bun

This guide shows you how to send transactional emails using Sequenzy in a Bun application.

## Prerequisites

* A Sequenzy account with an [API key](/authentication)
* A [verified sending domain](/guides/domain-verification)
* [Bun](https://bun.sh) installed

## 1. Install

Install the Sequenzy SDK:

```bash theme={null}
bun add sequenzy
```

## 2. Create an Email Template

Create a React Email component for your email template:

```tsx email-template.tsx theme={null}
import * as React from "react";

interface WelcomeEmailProps {
  firstName: string;
}

export function WelcomeEmail({ firstName }: WelcomeEmailProps) {
  return (
    <div>
      <h1>Welcome, {firstName}!</h1>
      <p>Thanks for signing up. We're excited to have you on board.</p>
    </div>
  );
}
```

<Note>
  You can use [React Email](https://react.email) components to build beautiful,
  responsive email templates. See our [React Email guide](#using-react-email)
  below for more details.
</Note>

## 3. Send the Email

Create your Bun server and send an email:

```tsx index.tsx theme={null}
import Sequenzy from "sequenzy";
import { render } from "@react-email/render";
import { WelcomeEmail } from "./email-template";

const client = new Sequenzy({
  apiKey: process.env.SEQUENZY_API_KEY!,
});

const server = Bun.serve({
  port: 3000,
  async fetch() {
    const { data, error } = await client.transactional.send({
      to: "user@example.com",
      subject: "Welcome to Our Platform!",
      body: await render(WelcomeEmail({ firstName: "John" })),
    });

    if (error) {
      return new Response(JSON.stringify({ error }), { status: 400 });
    }

    return new Response(JSON.stringify({ data }));
  },
});

console.log(`Server running at http://localhost:${server.port}`);
```

## 4. Run

Start your server:

```bash theme={null}
bun run index.tsx
```

Visit `http://localhost:3000` to trigger the email.

## Using Templates

Instead of rendering HTML directly, you can use pre-built templates from the Sequenzy dashboard:

```tsx theme={null}
const { data, error } = await client.transactional.send({
  to: "user@example.com",
  slug: "welcome-email",
  variables: {
    firstName: "John",
    dashboardUrl: "https://app.example.com/dashboard",
  },
});
```

## Using React Email

[React Email](https://react.email) provides a set of components for building responsive emails. Install it alongside Sequenzy:

```bash theme={null}
bun add @react-email/components @react-email/render
```

Create a more sophisticated template:

```tsx email-template.tsx theme={null}
import {
  Body,
  Button,
  Container,
  Head,
  Heading,
  Html,
  Preview,
  Text,
} from "@react-email/components";
import * as React from "react";

interface WelcomeEmailProps {
  firstName: string;
  dashboardUrl: string;
}

export function WelcomeEmail({ firstName, dashboardUrl }: WelcomeEmailProps) {
  return (
    <Html>
      <Head />
      <Preview>Welcome to our platform</Preview>
      <Body style={{ fontFamily: "sans-serif", padding: "20px" }}>
        <Container>
          <Heading>Welcome, {firstName}!</Heading>
          <Text>
            Thanks for signing up. Get started by visiting your dashboard:
          </Text>
          <Button
            href={dashboardUrl}
            style={{
              backgroundColor: "#c95a3c",
              color: "white",
              padding: "12px 24px",
              borderRadius: "6px",
            }}
          >
            Go to Dashboard
          </Button>
        </Container>
      </Body>
    </Html>
  );
}
```

Then render and send:

```tsx theme={null}
import { render } from "@react-email/render";
import { WelcomeEmail } from "./email-template";

const html = await render(
  WelcomeEmail({
    firstName: "John",
    dashboardUrl: "https://app.example.com/dashboard",
  })
);

await client.transactional.send({
  to: "user@example.com",
  subject: "Welcome to Our Platform!",
  body: html,
});
```

## Next Steps

<CardGroup cols={2}>
  <Card title="React Email Components" icon="react" href="https://react.email/docs/components/html">
    Explore all available React Email components
  </Card>

  <Card title="Transactional Emails" icon="envelope" href="/concepts/transactional-emails">
    Learn more about transactional emails
  </Card>
</CardGroup>
