editorcn pro

Email Composer

A Gmail-style email client template for React and shadcn/ui with folders, labels, threaded messages, a Gmail-style compose window, recipient chips, attachments, signatures and schedule send. Built on Tiptap.

A complete email client for React, built on shadcn/ui and Tiptap. The sidebar has New message, folders (Inbox, Starred, Sent, Scheduled, Drafts, Archive, Trash) with counts, colored labels (create one with the + next to Labels, delete one from its ⋯ menu), and the signed-in user with an optional account menu at the bottom. The message list has search (/), an All and Unread filter, date groups, and hover actions to archive, mark as unread, or delete. The reading pane shows the thread with older messages collapsed to one line, sender details, relative times, newer and older arrows, attachments you can download, labels, and star, archive, delete and label actions.

New messages, replies, forwards and saved drafts all open in one compose window at the bottom right, like Gmail: it stays open while you browse, and you can minimize it or expand it to full screen. It has a From picker, To, Cc and Bcc fields with contact suggestions and address checks, a subject, a rich text body with a bubble menu and formatting controls, attachments (pick, paste or drop), your signature, and a Send button with schedule presets or a custom date and time. Closing the window keeps the draft in Drafts.

Installation

$ pnpm dlx shadcn@latest add @editorcn-pro/email-composer

Usage

onSend receives the draft: from, to, cc, bcc, subject, the body as Tiptap JSON in content, and attachments. The raw files arrive as files. Resolve to add the message to the thread or to Sent. Throw to keep the composer open and show your error message.

import { EmailComposer } from "@/components/templates/email-composer";
 
export const Mail = () => (
  <EmailComposer
    accounts={[{ email: "robert@acme.com", name: "Robert Fox" }]}
    onSend={async (draft, { files, scheduledAt, signal }) => {
      const body = new FormData();
      body.append("draft", JSON.stringify(draft));
      for (const file of files) body.append("files", file);
      if (scheduledAt) body.append("scheduledAt", scheduledAt);
      const res = await fetch("/api/mail/send", {
        body,
        method: "POST",
        signal,
      });
      if (!res.ok) throw new Error("Couldn't send. Try again.");
    }}
    signature={"Best regards,\nRobert"}
  />
);

To turn the body into HTML for your mail provider, render draft.content with the Static Renderer or Tiptap's generateHTML.

Threads and drafts

Pass initialThreads to fill the mailbox and initialThreadId to open one. Each thread has a folder (inbox, sent, archive or trash), its messages, and optional unread, starred and labels. Starred, Sent and Scheduled are views across folders: Sent shows threads with a message from one of your accounts, and Scheduled shows threads with a message whose scheduledAt is in the future.

onThreadsChange gets every thread after a change (read state, star, labels, moves, new messages), onDraftsChange gets every draft after one is saved, sent or discarded, and onLabelsChange gets every label after one is created or deleted, so you can store them. Deleting a label removes it from every thread. Replies keep their threadId, and onSend gets it too.

<EmailComposer
  accounts={accounts}
  contacts={contacts}
  initialDrafts={drafts}
  initialThreads={threads}
  labels={[
    { color: "amber", id: "clients", name: "Clients" },
    { color: "emerald", id: "invoices", name: "Invoices" },
  ]}
  onDraftsChange={(drafts) => saveDrafts(drafts)}
  onThreadsChange={(threads) => saveThreads(threads)}
  onSend={(draft, options) => sendToYourApi(draft, options)}
/>

Press c to write a message, / to search, and ⌘ Enter (or Ctrl Enter) to send. Below 1024px the folders open as a drawer, and below 640px the list and the message show one at a time.

Recipients and attachments

contacts and everyone in your threads show up as suggestions while you type in To, Cc or Bcc. Press Enter, Tab or a comma to add an address, paste a comma separated list to add several, and press Backspace to remove the last one. Invalid addresses are marked and block sending.

Attachments are added with the paperclip, by pasting, or by dropping files on the composer. Limit them with accept and maxAttachmentSize (in bytes). Uploading the files is up to your backend.

Props

PropTypeDescription
onSendfunctionGets the draft and { files, scheduledAt, signal, threadId }; throw to show errors
accountsEmailContact[]Addresses you send from, shown in the From picker
contactsEmailContact[]Recipient suggestions
initialThreadsEmailThread[]Threads in the mailbox
initialThreadIdstringThread to open first
onThreadsChangefunctionGets every thread after a change
initialDraftsEmailDraft[]Drafts in the Drafts folder
onDraftsChangefunctionGets every draft after a change
labelsEmailLabel[]Starting labels with a name and a color (emerald, amber, rose or sky)
onLabelsChangefunctionGets every label after one is created or deleted
signaturestringAdded under new messages and replies; line breaks are kept
brand{ name, logo? }Name and logo above the folders
currentUserEmailUserAvatar, name and a second line shown at the bottom of the sidebar, default the first account
userMenuEmailUserMenuItem[]Items in the menu that opens from the user row: label, onSelect, optional icon, destructive and separator
acceptstringAllowed attachment types, default any
maxAttachmentSizenumberLargest attachment in bytes
placeholderstringBody placeholder
classNamestringOuter container classes