# Mail Composer

> Writing a mail: from (a select when you may send from several addresses), To, Cc and Bcc as RecipientInput, subject, the text in the RichTextEditor, the signature with a switch, and attachments.

Component · Forms · Halo kit · [Live page](https://ui.twentyfirst.media/halo/components/MailComposer/)

Writing a mail: from (a select when you may send from several addresses), To, Cc and Bcc as `RecipientInput`, subject, the text in the `RichTextEditor`, the signature with a switch, and attachments.

- **Attachments**: `onFiles` gets the files picked on the device; `attachSources` adds places such as "From Drive" (your picker). Uploads show their progress; Send waits for them.
- **Draft**: the whole draft goes to `onChange`; `saved` and `savedAt` show "Draft saved 10:42".
- **Sending**: Send or ⌘/Ctrl+Enter. With `onUndoSend` a toast offers Undo for `undoSeconds` (default 10); hold the mail that long. "Send later" picks a date and time (`onSchedule`).

## Example

```tsx
import * as React from "react";
import { MailComposer, Toaster, toast } from "@twentyfirstmedia/halo";
import type { MailDraft } from "@twentyfirstmedia/halo";
import { PEOPLE } from "./_mail";

const SENDERS = [
  { address: "mara@example.com", name: "Mara Ellis" },
  { address: "support@example.com", name: "Support" },
  { address: "billing@example.com", name: "Billing" },
];

export default function Preview() {
  const [draft, setDraft] = React.useState<MailDraft>({
    from: "mara@example.com",
    to: [PEOPLE[0]!],
    cc: [],
    bcc: [],
    subject: "Pricing review moved to Thursday",
    html: "<p>Hi Lena,</p><p>we moved the pricing review to <b>Thursday at 11:00</b> so Growth can join.</p>",
    signature: true,
    attachments: [
      { id: "a1", name: "pricing-v3.pdf", size: "1.2 MB" },
      { id: "a2", name: "seat-model.xlsx", size: "84 KB" },
    ],
  });
  return (
    <>
      <MailComposer
        senders={SENDERS}
        value={draft}
        onChange={setDraft}
        suggestions={PEOPLE}
        signature={"Mara Ellis\nHead of Operations · Example Inc."}
        saved="saved"
        savedAt={new Date(2026, 3, 16, 10, 42)}
        onSend={() => {}}
        onUndoSend={() => toast("Sending cancelled")}
        onSchedule={() => toast("Scheduled")}
        onFiles={() => {}}
        attachSources={[{ label: "From Drive", icon: "folder", onClick: () => {} }]}
        onDiscard={() => {}}
      />
      <Toaster />
    </>
  );
}
```

## Props

### MailComposer

| Prop | Type | Notes |
| --- | --- | --- |
| `senders?` | `{ address: string; name?: string }[]` | Addresses you may send from; a select when there are several. |
| `value?` | `MailDraft` | The draft (controlled) / initially / on every change (save it as a draft). |
| `defaultValue?` | `Partial<MailDraft>` |  |
| `onChange?` | `(draft: MailDraft) => void` |  |
| `suggestions?` | `MailRecipient[]` |  |
| `suggest?` | `(typed: string) => MailRecipient[] \| Promise<MailRecipient[]>` |  |
| `signature?` | `ReactNode` | The signature shown under the text, with a switch to leave it out. |
| `onSend?` | `(draft: MailDraft) => void` | Send (also ⌘/Ctrl+Enter); on only with valid recipients and no upload running. |
| `onUndoSend?` | `(draft: MailDraft) => void` | Shows "Message sent" with Undo in a toast (needs a `<Toaster/>`). Hold the mail for `undoSeconds` and drop it when this is called. |
| `undoSeconds?` | `number` | How long Undo stays (default 10 s). |
| `onSchedule?` | `(draft: MailDraft, at: Date) => void` | "Send later" with a date and time. |
| `onFiles?` | `(files: File[]) => void` | Files picked on this device (add them to `attachments` and upload). |
| `attachSources?` | `{ label: string; icon?: IconName; onClick: () => void }[]` | More places to attach from, e.g. "From Drive" (opens your picker). |
| `onRemoveAttachment?` | `(id: string) => void` |  |
| `saved?` | `"saving" \| "saved" \| "error" \| null` | Draft state: saving, saved (at `savedAt`) or failed. |
| `savedAt?` | `Date` |  |
| `onDiscard?` | `() => void` |  |
| `sending?` | `boolean` |  |
| `title?` | `string` | Heading (default "New message"). |
| `placeholder?` | `string` |  |
| `minHeight?` | `number` |  |
| `autoFocus?` | `boolean` |  |
| `footer?` | `ReactNode` | More controls in the footer. |
| `className?` | `string` | Extra class on the root element. |
| `style?` | `CSSProperties` | Inline style on the root element. |

### RecipientInput

| Prop | Type | Notes |
| --- | --- | --- |
| `label` | `string` | Required |
| `hideLabel?` | `boolean` |  |
| `id?` | `string` |  |
| `value?` | `MailRecipient[]` | The addresses (controlled) / initially / on change. |
| `defaultValue?` | `MailRecipient[]` |  |
| `onChange?` | `(value: MailRecipient[]) => void` |  |
| `suggestions?` | `MailRecipient[]` | Known addresses, filtered while typing. |
| `suggest?` | `(typed: string) => MailRecipient[] \| Promise<MailRecipient[]>` | Or ask your server while typing (debounced). |
| `validate?` | `(address: string) => boolean` | Your own address check (default: a plain e-mail pattern). |
| `placeholder?` | `string` |  |
| `hint?` | `string` |  |
| `error?` | `string` |  |
| `disabled?` | `boolean` |  |
| `autoFocus?` | `boolean` |  |
| `className?` | `string` | Extra class on the root element. |
| `style?` | `CSSProperties` | Inline style on the root element. |

### RichTextEditor

| Prop | Type | Notes |
| --- | --- | --- |
| `label?` | `ReactNode` |  |
| `hideLabel?` | `boolean` | Hide the label visually; it stays the editor's accessible name. |
| `defaultValue?` | `string` |  |
| `value?` | `string` |  |
| `onChange?` | `(html: string) => void` |  |
| `placeholder?` | `string` |  |
| `variables?` | `{ key: string; label: string }[]` |  |
| `maxLength?` | `number` |  |
| `minHeight?` | `number` |  |
| `footer?` | `ReactNode` |  |
| `hint?` | `ReactNode` |  |
| `error?` | `ReactNode` |  |
| `disabled?` | `boolean` |  |
| `className?` | `string` | Extra class on the root element. |
| `style?` | `CSSProperties` | Inline style on the root element. |
