© 2026 Hedgehog Software, LLC
wrangler.toml
[[workflows]] name = "process-incoming-emails" binding = "PROCESS_INCOMING_EMAILS_WORKFLOW" class_name = "ProcessIncomingEmailsWorkflow"
types.ts
import type { Workflow } from '@cloudflare/workers-types'; export type Bindings = { // ...other bindings PROCESS_INCOMING_EMAILS_WORKFLOW: Workflow; };
src/index.ts
import { app } from './app'; // Hono app import type { Bindings } from './types'; import { handleForwardingIncomingEmails } from './incoming-emails/forward-email-handler'; export { ProcessIncomingEmailsWorkflow } from './incoming-emails/workflow'; const handler = { fetch: app.fetch, async email(message, env, ctx) { await handleForwardingIncomingEmails(message, env, ctx); }, } satisfies ExportedHandler<Bindings>;
./incoming-emails/forward-email-handler
export const handleForwardingIncomingEmails = async ( message: ForwardableEmailMessage, env: Bindings, _ctx: ExecutionContext, ) => { return withLogTags( { tags: { handler: 'email', requestId: crypto.randomUUID(), }, }, async () => { const [address] = addressParser(message.to); if (!address?.address) { logger.warn('No email address found in `to` field'); return message.setReject('No email address found in `to` field'); } logger.log('Workflow defined', { defined: !!env.PROCESS_INCOMING_EMAILS_WORKFLOW, // <-- Not defined here! }); // await env.PROCESS_INCOMING_EMAILS_WORKFLOW.create({ // params: { // message, // }, // }); } ) }
./incoming-emails/workflow
export class ProcessIncomingEmailsWorkflow extends WorkflowEntrypoint< Bindings, Params > {}