Workflow Approvals with Resend
When a Mastra workflow suspends for human review, how does the reviewer send their decision back? This template uses Resend to email the proposal with signed Approve and Decline links. The reviewer opens a link and confirms their choice in the browser. Mastra then resumes the original run and follows the selected path.
Why we built this
Reviewers often work outside the app that started the workflow. Email brings the proposal and decision links to their inbox, where they can review it on their own time. The template shows how to keep that handoff reliable across restarts and repeated clicks by storing the suspended run and recording the decision before queuing the resume.
Demo
Prerequisites
- Install a supported release of Node.js. Node.js requirements
- OpenAI API key for
OPENAI_API_KEY. - Resend API key and sender for
RESEND_API_KEYandRESEND_FROM. For a first run, useonboarding@resend.devas the sender and your Resend account email asDEMO_APPROVER_EMAIL. Use a verified sending domain with click tracking disabled to test direct approval links for other recipients. Local email setup - ngrok account and CLI for local development only, with your account token configured locally. Set
APPROVAL_BASE_URLto your assigned HTTPS origin and disable account-level Full Capture. Local tunnel setup - Approval signing secret for
APPROVAL_SIGNING_SECRET. Generate it during setup and keep the same value across restarts.
Quickstart 🚀
These steps run Studio locally. For a hosted first run, start with the Mastra Platform deployment guide.
- Clone the template
- Run
npx create-mastra@latest workflow-approvals-resend --template workflow-approvals-resendto scaffold the project and install its dependencies. - Run
cd workflow-approvals-resend.
- Run
- Configure local approvals
- Run
cp .env.example .envand fill in the values from Prerequisites. - Run
node -e "console.log(require('node:crypto').randomBytes(32).toString('base64url'))"and save the output asAPPROVAL_SIGNING_SECRET. KeepDATABASE_PROVIDER=localandAPPROVAL_MODE=confirmationfor this walkthrough.
- Run
- Start Mastra and ngrok
- Run
npm run dev. In a second terminal in the project directory, runnpm run tunnel:approvals.
- Run
- Approve a deployment plan
- In Mastra Studio, open Workflows, select
ai-deployment, and run it with{"request":"Plan a rollout for a fictional inventory dashboard"}. - The run drafts a plan and suspends while Resend sends the approval email. Choose Approve in the email, then Confirm approval in the browser. Return to the original run in Studio and check that it completes with
protectedEffect: truefor the simulated deployment.
- In Mastra Studio, open Workflows, select
Try it out
- Decline a publication draft. Run
ai-content-publishingwith{"request":"Draft a launch announcement for a weekly inventory report"}. Confirm Decline from the email and check that the run reportsprotectedEffect: false. - Try the one-click demo. Run
simulated-publicationwith{"reviewerEmail":"you@example.com","draftId":"demo-draft","revision":1}. Use an inbox your sender can reach. The browser submits the selected decision automatically when the link opens. Review modes and expected results - Restart with an approval pending. Start a run, wait for its email, then restart Mastra with the same database, origin, and signing secret. Use the original link before it expires and check that the same run resumes. Operations and recovery
Customization
- Ask a coding agent to trace the proposal, approval, and outcome steps in
src/mastra/workflows/use-cases.tsand propose a plan. For example, “Adapt this workflow to email a reviewer before scheduling a simulated data export.” - Change what reviewers see in
src/mastra/approvals/email.ts, or reusecreateApprovalStepin your own workflow. Code walkthrough
Documentation
- Local setup and example workflows
- Environment variables and database setup
- Operations and recovery
- Verified reviewer sessions
Deploy to Mastra Platform
Set DATABASE_PROVIDER=turso in the Deploy form and select Create project. Attach Turso to production while the first build runs. Once the deployment is Ready, use the Server origin from Overview for APPROVAL_BASE_URL. Save the production variables and select Restart saved changes before starting a workflow in Studio. Deploy and verify an email decision
About Mastra templates
This template lives in the Mastra monorepo and shows how to add email review to a suspended workflow. Contributing
