This Workers script sends emails using the Resend API. It uses Cloudflare Queue to decouple sending emails.
- Email sending functionality using Resend
- Multiple email templates (Sign In, Sign Up, Order Confirmation)
- Queue-based email sending
- Cloudflare Workers account
- Resend API key
- Install the project dependencies:
# make sure you are in the correct directory
# cd server
npm install
- Set the Resend API key
- Rename
.dev.vars.example
to.dev.vars
- Replace
re_1234567890
with your Resend API key
- Create a D1 database
npx wrangler d1 create e-com
- Update the bindings
- Update the
[[d1_database]]
binding inwrangler.toml
- Create tables
npx wrangler d1 execute e-com --file="./schema/init.sql"
- Create a queue
# Creat Queue to handle orders
npx wrangler queues create order-queue-demo
# Create Queue to handle user sessions
npx wrangler queues create user-session-queue-demo
Start the local development server:
npm run dev
- Add table to the remote database
npx wrangler d1 execute e-com --file="./schema/init.sql" --remote
- Deploy the project to Cloudflare Workers:
npm run deploy
Contributions are welcome! Please feel free to submit a Pull Request.