Skip to content

Black Friday

Annual Pro is $90 for the first year, normally $120. Or start monthly at $6 for two months, then $12.

Ends Dec 4, 11:59 PM PT.

Create an account
← Public packages

@danj/hey-email

HEY.com email for Kody: search threads, read messages, download PDF attachments, and write drafts. Sending is barred until you allow it.

FollowFork

Integrations

Version
2.0.0
License
Published
November 30, 2026
Pinned commit
3f72e37
Rating
No ratings yet
Forks
0
Adaptation effort
—

README

Agent docs

@danj/hey-email

Intent

Let your agents, and the Kody packages they build, search, read, and draft your HEY mail. The package calls HEY at app.hey.com, through the same API that HEY's CLI and SDK use. Kody never runs the hey CLI. You run it once on your computer, to sign in for Kody.

Sending is barred until you allow it. SENDING in src/config.js is the switch. While it is 'barred', no function sends mail, and your agent saves drafts for you to send. The section "The sending switch" explains how to allow sending.

The package is publish-locked on Kody. A change goes live only after you review it and click Promote this commit.

What you can ask your agent

Ask your agent for any of these:

  • "Find the invoice from Acme last week and read me its total from the PDF."
  • "Summarize my thread with Ada."
  • "Draft a reply to Ada that says the Tuesday slot works." The agent saves a reply draft and gives you its edit link.
  • "Email Bob that I'm running late." The agent saves a new draft addressed to Bob and gives you its edit link.
  • "Move this Logos newsletter thread to Paper Trail." The agent moves that one thread. Other mail from the same sender stays where it is.

You do these yourself:

  • Send each draft. Open its edit link in HEY, check the text and the recipients, and send.
  • Sign in to HEY, and save that login in Kody with the setup script.
  • Review and promote each change to the package on Kody.
  • Decide whether sending is ever allowed.

What it does

Each ./name export imports as kody:@danj/hey-email/name.

ExportWhat it doesHEY calls
kody:@danj/hey-emailReturns your HEY { id, name }. Use it as a shallow check of your setup.GET /identity
./searchSearches your mail. Pass limit greater than 10 to fetch further pages.GET /advanced_search.json, then ?page=2 and so on
./paper-trailMoves one thread to the Paper Trail, by topic id or entry id.GET /boxes.json, then POST /topics/{id}/moves.json
./boxesLists your boxes, such as the Imbox and the Feed.GET /boxes.json
./topicReads one thread.GET /topics/{id}.json
./entriesLists the messages in a thread.GET /topics/{id}/entries.json
./messageReads one message with its HTML body.GET /messages/{id}.json
./attachmentsLists PDF attachments on a message, then downloads one file as base64. The default export is listPdfs: metadata only, no bytes.GET /messages/{id}.json to list. One GET for a chosen PDF.
./draftsLists, reads, and saves drafts with their recipients. HEY keeps each saved draft as a draft. It also exports the three send functions.GET /entries/drafts.json, GET /messages/{id}/edit.json, POST /messages.json, POST /entries/{id}/replies.json
./replySaves a reply draft on a thread.GET /entries/{id}/replies/new.json, POST /entries/{id}/replies.json
./sendsendMessage, sendReply, and sendDraft.None while sending is barred. While it is allowed, a confirmed send calls POST /messages.json, POST /entries/{id}/replies.json, or PUT /messages/{id}.json.

AGENTS.md lists each function's inputs, results, and errors.

The default export of ./attachments is listPdfs. It returns metadata only (index, filename, contentType, url, filesize) and has no bytes. There is no combined download of every file. Call downloadPdf for one PDF as base64.

Set it up

You do the steps that need your HEY sign-in or your review. Your agent does the rest. Your HEY tokens never pass through the agent.

Kody keeps your HEY login as one login credential named hey. It holds the refresh token and the install id of Kody's HEY login. Kody runs HEY's token refresh, saves a new refresh token when HEY returns one, and places the access token on each request to app.hey.com. The package never sees either token.

  1. You need a HEY account. HEY is a paid 37signals product with a free trial at hey.com. A @hey.com address and a HEY for Domains address both work.

  2. You install the HEY CLI on your computer, version 1.4.0 or later. Follow the hey-cli install guide. You also need Node 22 or later, and a checkout of this package's repository. If the Kody CLI is not signed in, run npx --yes @kodycodes/cli@latest auth login.

  3. You sign in to HEY for Kody, in a new folder. To HEY, Kody is then a separate device, like a second computer. Your own CLI login stays as it is. Run these lines in one terminal window, and keep that window for steps 4 and 6.

    HEY_KODY=$(mktemp -d)
    XDG_CONFIG_HOME="$HEY_KODY" HEY_NO_KEYRING=1 hey auth login
    XDG_CONFIG_HOME="$HEY_KODY" HEY_NO_KEYRING=1 hey auth status

    hey auth login opens HEY's sign-in page in your browser. HEY_NO_KEYRING makes the CLI save this login in the folder, not in your keychain. In the status, the Auth: line must show oauth, and the Storage: line must show file. Do not add --cookie or --token to the login. Those logins store no refresh token, so Kody cannot use them. HEY can email you about a sign-in from a new device.

  4. You save the login in Kody. From the checkout, in the same window, run:

    node scripts/provision-login.mjs --dir "$HEY_KODY"

    The script reads the refresh token and the install id from the folder and sends them to Kody on stdin. It never prints them. Its last line must be status=pass. It stops, and saves nothing, when Kody already has a credential named hey. If it prints Save unconfirmed, check hey in Kody Credentials before you run it again.

  5. In Kody Credentials, map hey to this package and to each package that imports it, if Kody did not. Tell your agent. Your agent runs identity(). It must return your HEY id and name.

  6. You delete the folder with rm -rf "${HEY_KODY:?}". Kody now holds the only copy of this login. Nothing else refreshes its tokens, so Kody's copy stays valid.

  7. Your agent locks the package on Kody, if it is not locked yet. From then on, each change waits on the package page until you click Promote this commit. Only you can unlock it, on the package's settings page.

Reconnect

When Kody reports login_needs_reconnect, HEY no longer accepts the saved refresh token. Run setup steps 3, 4, and 6 again, and add --reconnect to the script:

node scripts/provision-login.mjs --dir "$HEY_KODY" --reconnect

Its last line must be status=pass. The script saves the new value onto the same hey, which keeps its id and mappings.

Use it from another package

The agent that builds your package follows these steps.

  1. Add "@danj/hey-email": "*" to kody.dependencies, and import the exports as kody:@danj/hey-email/<export>. In a fork of this package, use your own scope instead of @danj.
  2. Read AGENTS.md for each function's inputs, results, and errors.
  3. Your package bundles a snapshot of this one. After each change here, republish your package.

The sending switch

SENDING in src/config.js is the switch. Its committed value is 'barred'. Only you decide to change it.

SENDING = 'barred' (committed)SENDING = 'allowed'
sendMessage, sendReply, sendDraftReturn the barred result, with barred: true and sent: false. No request reaches HEY.Send when confirm is exactly true. Otherwise, return a dry run, and send nothing.
createDraft, createReplyDraftSave a draft with its recipients. HEY does not send it.Same.

An agent must not change SENDING to finish an email request. While sending is allowed, an agent still saves a draft, unless you ask it in plain words to send now. An agent must not send from an unattended run, such as a reminder job. The code does not enforce these two rules, so the lock on Kody matters.

Allowing sending

  1. You change SENDING to 'allowed'. You can commit to main, or open a pull request. You can also ask your agent in plain words to make this change.
  2. Three test files and the test hook pin the barred value. The same commit updates test/sending-gate.test.js, test/sending-allowed.test.js, test/redirects.test.js, and test/hooks.mjs. It also updates the two package descriptions in package.json.
  3. The sending-policy-suite check fails on a branch or pull request that sets 'allowed' while main is still 'barred'. So a pull request with this change shows a failed check. You can still merge it. After that, later branches carry 'allowed' from main, and the check passes them.
  4. Your agent publishes the package to Kody. You review the change on the package page, and click Promote this commit. Then your agent republishes the packages that use this one.

Security posture

CredentialWhat it holdsKody sends it toKody updates it
hey (kind login)The refresh token and the install id of Kody's HEY loginapp.hey.com/oauth/tokens, in HEY's refresh requestWhen HEY returns a new refresh token
The access tokenKody gets it from each refresh, and keeps it until it expires.app.hey.com, in the Authorization headerAt each refresh

The package declares the need hey in kody.credentials, with kind login. It sends each app.hey.com request through credential('hey'), and holds no token. Every request asks Kody to fill secret placeholders only in headers (x-kody-secret-resolution: headers-only), so draft text that quotes a placeholder is sent as written.

What this design guarantees:

  • The access token goes only to app.hey.com. resolveHeyUrl refuses every other origin, and Kody sends the token only to the credential's host.
  • The package follows redirects itself. A redirect off app.hey.com drops the credential. PDF downloads continue to the file storage host as a plain GET. JSON calls refuse the redirect.
  • The package retries nothing. When app.hey.com answers 401 to a request with no body, Kody refreshes the token once and retries that request once. A write that gets a 401 is not replayed. A 401 from the PDF storage host starts no refresh.
  • No function sends mail while SENDING is 'barred'.
  • The package is publish-locked. No change, including a change to SENDING, goes live on Kody before you promote it.

What it leaves open:

  • Any code that imports this package can read all your mail and save drafts. While SENDING is 'allowed', that code can also send mail.
  • GitHub refuses branch protection on this private repository on the free plan. So the sending-policy-suite check does not block a merge or a push to main. The lock on Kody is the control that holds.

Troubleshooting

ErrorCauseFix
HEY 401 <path> on a readHEY refused the token, and Kody's one retry did not help.Wait a minute, and read again. If it still fails, follow the Kody error code that the next read returns.
HEY 401 <path> on a writeHEY refused the token. Kody does not retry a request with a body, and neither does the package.See "After a write fails with HEY 401" below.
credential_unboundThe package's need hey is not mapped to a credential.In Kody Credentials, map hey to this package. If hey does not exist, run setup steps 3 to 6.
login_failedKody's refresh request to HEY failed.Wait retryAfterSeconds, or a minute, then try again.
login_retry_laterKody is waiting after a recent refresh failure.Wait retryAfterSeconds, or a minute, then try again.
login_needs_reconnectHEY refused the saved refresh token. A token from a --cookie or --token login gives the same error.Follow "Reconnect" under "Set it up".
Refusing to send HEY credentials to <origin>A URL outside app.hey.com reached the package, such as a PDF link in an email. downloadPdf stops there and returns no file.Open the file in HEY.
Refusing to follow HEY redirect to <origin>HEY redirected a JSON call off app.hey.com.None. The package refuses it.
listPdfs returns no PDFsThe HTML came from the entries list, which omits attachments.Pass the message id.

After a write fails with HEY 401

A write that throws HEY 401 <path> may or may not have taken effect.

  1. Check whether it happened: listDrafts() for a draft, or getTopic() for a reply or a move.
  2. Make a read, such as identity().
  3. If the read also fails with a 401 or login_retry_later, wait retryAfterSeconds, or a minute, and read again. On login_needs_reconnect, you reconnect: a fresh hey auth login, then the script with --reconnect, as "Reconnect" under "Set it up" shows. Its last line must be status=pass.
  4. Repeat the write only after a read succeeds and the check shows that the write did not happen.

Development

The package has no dependencies. npm test runs the Node test runner. The test hooks in test/hooks.mjs stub kody:runtime: its credential() records the key and marks each request it sends. The hooks also load a second copy of src/ where SENDING is 'allowed'. The committed file stays 'barred'.

The sending-policy-suite GitHub Actions workflow runs on Node 22, on pull requests and on pushes to every branch except main. It runs scripts/sending-policy-check.mjs, then npm test. The script fails when the branch sets SENDING to 'allowed' and origin/main does not. Its last lines are status=pass, status=fail, or status=blocked when it cannot read origin/main, with a reason= line when it does not pass.

For your own terminal, use the HEY CLI directly. It also ships an agent skill and an MCP server, described in the hey-cli agent guide.

Credits and license

This package is a fork of @noah/hey-email on Kody, by Noah (HiThereHey). Noah wrote the first HEY API wrapper, the draft and send functions, and the token refresh. Daniel Jomphe's fork adds the redirect rules, the sending switch, the HEY SDK request format, the separate Kody login, and the move of the tokens into the Kody login credential hey.

MIT. LICENSE keeps Noah's copyright notice, and adds Daniel Jomphe's for the fork's changes.

Report this listing

Log in to report this listing.