Documentation menu
Documentation

Email

Route inbound mail to a durable agent and send replies from the same identity.

Start from a fresh project

This guide is self-contained. Create an empty Ayjnt project, then replace the starter agent with the files shown below. Run commands from the new project directory unless a step says otherwise.

terminal
bunx ayjnt new try-email --empty
cd try-email
bun install

# remove agents/alive once you are ready to add the guide's files

Handle mail as an event

Override onEmail() for inbound messages and use native replyToEmail() or sendEmail() for outbound mail. Secure reply routing signs agent identity headers so replies return to the correct durable instance.

Email contents can contain prompt injection. Parse it as untrusted input, limit tools available during mail handling, and require approval before external side effects.

Run it and verify the result

Send a message to the configured local part and confirm onEmail() receives it and selects the expected agent instance.

terminal
bun run build
bun run dev

# the local app is now available at http://localhost:8787