Skip to content

Latest commit

 

History

History
146 lines (106 loc) · 3.21 KB

File metadata and controls

146 lines (106 loc) · 3.21 KB

Quick Start Guide

🚀 Final Setup (10 minutes)

The worker is deployed! Just complete these 2 quick steps in the Cloudflare dashboard:

Step 1: DNS (3 minutes)

  1. Open: https://dash.cloudflare.com/
  2. Click on domain: offloadmy.work
  3. Left sidebar → DNSRecords
  4. Click Add record
  5. Fill in:
    • Type: A or AAAA
    • Name: email
    • IPv4/IPv6: Use Cloudflare's worker proxy (auto-configured)
    • Proxy status: ✅ Proxied (orange cloud)
  6. Click Save

Note: The route email.offloadmy.work/* is already configured in the worker. DNS just makes it accessible.

Step 2: Email Routing (7 minutes)

  1. Still in Cloudflare dashboard for offloadmy.work
  2. Left sidebar → EmailEmail Routing
  3. If not enabled: Click Enable Email Routing and follow prompts
  4. Go to Email Workers or Routes tab
  5. Click Create route or Add rule
  6. Fill in:
    • Rule name: Catch-all to worker
    • When email is received: Choose Catch-all or type *@offloadmy.work
    • Then: Select Send to Worker
    • Worker: Select offload-email from dropdown
  7. Click Save or Create

Done! Your email worker is now live.


🧪 Test It

1. Test the API

cd /Users/netanelgilad/development/offload-email-worker
./test-api.sh

Should output stats and list emails.

2. Send a Test Email

Send an email from your personal email to:

test@offloadmy.work

Subject: "Testing my new email worker" Body: "Hello from Cloudflare!"

3. Check if It Was Received

export API_TOKEN=$(cat ~/.config/offload/email-worker.json | grep api_secret | cut -d'"' -f4)

curl -H "Authorization: Bearer $API_TOKEN" \
  https://email.offloadmy.work/api/emails | jq '.emails[0]'

You should see your test email! 🎉


📱 Quick API Examples

Get your API token:

export API_TOKEN=$(cat ~/.config/offload/email-worker.json | grep api_secret | cut -d'"' -f4)

List all emails:

curl -H "Authorization: Bearer $API_TOKEN" \
  https://email.offloadmy.work/api/emails

Get stats:

curl -H "Authorization: Bearer $API_TOKEN" \
  https://email.offloadmy.work/api/stats

List only unread:

curl -H "Authorization: Bearer $API_TOKEN" \
  "https://email.offloadmy.work/api/emails?unread=true"

Mark email as read:

# Replace EMAIL_ID with actual ID from list
curl -X PATCH \
  -H "Authorization: Bearer $API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"read": true}' \
  https://email.offloadmy.work/api/emails/EMAIL_ID

🛠️ Useful Commands

# Deploy changes
npm run deploy

# View live logs
npm run tail

# Local development
npm run dev

# Query database
npm run db:remote "SELECT COUNT(*) FROM emails"

📚 More Info

  • Full API docs: README.md
  • Deployment details: DEPLOY_LOG.md
  • Troubleshooting: DEPLOY_LOG.md → "🐛 Troubleshooting" section

🎉 You're All Set!

Your email worker is now:

  • ✅ Receiving emails at *@offloadmy.work
  • ✅ Storing them in D1 database
  • ✅ Exposing them via REST API
  • ✅ Protected with authentication
  • ✅ CORS-enabled for web apps

Build something cool! 🚀