Hooks

useDocyrusEmailComposer

Wires the native EmailComposer to the Docyrus messaging API — sender accounts, @ mention users and the send mutation, with composer state managed for you.

iOSAndroidExpo Go

Installation

pnpm dlx @docyrus/cli add @docyrus/rn-hooks-use-docyrus-email-composer
Required Packages(2 packages)
pnpm add @tanstack/react-query @docyrus/api-client

A verbatim port of the web hook (same options, result and query keys). It fetches GET /v1/messaging/email/accounts for the From picker and auto-selects the first user-accessible account, fetches GET /v1/users once for @ mentions (client-side filtering), and sends through POST /v1/messaging/email/accounts/{accountId}/send. It returns composerProps to spread onto EmailComposer. Both endpoints need the Messaging.Email.Send scope, and a QueryClientProvider must be mounted above it.

Usage

import { EmailComposer } from '@/components/docyrus-native/email-composer';
import { useDocyrusEmailComposer } from '@/hooks/docyrus-native/use-docyrus-email-composer';

function ReplyComposer({ client, to }) {
  const { composerProps, send, attachments } = useDocyrusEmailComposer({ client, initialTo: to });

  return (
    <EmailComposer
      {...composerProps}
      attachments={attachments}
      onSend={async () => {
        const result = await send({ attachments: [{ filePath: uploaded.fullPath, fileName: 'quote.pdf' }] });

        console.log(result.accepted, result.rejected);
      }} />
  );
}

send(overrides) takes storage-backed attachments ({ filePath, fileName?, mimeType? }) — upload the picked NativeFile to Docyrus storage first. The composer's own attachments ({ name, size }) are display metadata only.

API Reference

UseDocyrusEmailComposerOptions

OptionTypeDefaultDescription
clientRestApiClient-Authenticated REST client (required)
initialTo / initialCc / initialBcc / initialReplyTostring[][]Initial recipients
initialSubjectstring''Initial subject
initialBodystring''Initial HTML body
initialAccountIdstringfirst accessibleAccount to preselect
resetOnSendSuccessbooleantrueClear recipients / subject / body / attachments after a send
enabledbooleantrueToggle the queries
sendAsUserboolean-Default sendAsUser for every send
listAccountsEndpointstring/v1/messaging/email/accountsAccounts endpoint
sendEndpointstring/v1/messaging/email/accounts/{accountId}/sendSend endpoint
mentionsbooleantrueFetch /v1/users for mentions
mentionUsersEmailComposerMentionUser[]-Explicit mention users (skips the fetch)
listUsersEndpointstring/v1/usersUsers endpoint
slashCommandsEmailComposerSlashCommand[]-Passed through to the composer

UseDocyrusEmailComposerResult

FieldTypeDescription
composerPropsPick<EmailComposerProps, …>accounts, selection, to / cc / bcc, subject, body, mentionUsers, slashCommands, onSend, sending
accounts / selectedAccountDocyrusEmailAccount[] / DocyrusEmailAccount | nullRaw account DTOs
setSelectedAccountId(id: string) => voidChange the account
isLoadingAccounts / accountsError / refetchAccountsAccounts query state
mentionUsersEmailComposerMentionUser[]Resolved mention users
to / cc / bcc / replyTo / subject / body / attachments + settersComposer state
send(overrides?: DocyrusEmailSendOverrides) => Promise<DocyrusEmailSendResult>Send
isSending / sendError / lastSendResultMutation state
reset() => voidRestore the initial values

Types

TypeDescription
DocyrusEmailAccountAccount DTO (kind, provider, providerSlug, isUserAccessible, allowOverrideName, allowOverrideEmail, createdOn)
DocyrusEmailAttachment{ filePath, fileName?, mimeType? }
DocyrusEmailSendOverridesPer-send to, cc, bcc, replyTo, subject, body, sendAsUser, attachments, accountId
DocyrusEmailSendResult{ messageId, provider, accepted, rejected }
DocyrusEmailProvider'aws' | 'smtp' | 'mailgun' | 'resend' | 'microsoft-graph' | 'gmail'

On this page