|
| 1 | +# Deployment Guide |
| 2 | + |
| 3 | +## Prerequisites |
| 4 | + |
| 5 | +1. **Cloudflare Account**: Sign up at https://dash.cloudflare.com |
| 6 | +2. **Node.js**: v20 or higher |
| 7 | +3. **Wrangler CLI**: Installed via npm (included in dev dependencies) |
| 8 | + |
| 9 | +## Local Development |
| 10 | + |
| 11 | +### 1. Install Dependencies |
| 12 | + |
| 13 | +```bash |
| 14 | +npm install |
| 15 | +``` |
| 16 | + |
| 17 | +### 2. Configure Local Environment |
| 18 | + |
| 19 | +Create a `.dev.vars` file in the project root for local development: |
| 20 | + |
| 21 | +```bash |
| 22 | +PERSONAL_EMAIL=your-personal@example.com |
| 23 | +WORK_EMAIL=your-work@example.com |
| 24 | +MAILCHANNELS_API_KEY=your-mailchannels-key |
| 25 | +PINCODE=your-secret-pincode |
| 26 | +FROM_EMAIL=noreply@yourdomain.com |
| 27 | +FROM_NAME=MailRelay |
| 28 | +``` |
| 29 | + |
| 30 | +### 3. Run Locally |
| 31 | + |
| 32 | +```bash |
| 33 | +npm run dev |
| 34 | +``` |
| 35 | + |
| 36 | +Visit `http://localhost:8787` to test locally. |
| 37 | + |
| 38 | +## Production Deployment |
| 39 | + |
| 40 | +### Option 1: GitHub Actions (Automatic) |
| 41 | + |
| 42 | +#### Setup GitHub Secrets |
| 43 | + |
| 44 | +Go to your repository Settings → Secrets and variables → Actions, and add: |
| 45 | + |
| 46 | +1. **CLOUDFLARE_API_TOKEN** |
| 47 | + - Go to https://dash.cloudflare.com/profile/api-tokens |
| 48 | + - Create token with "Edit Cloudflare Workers" permissions |
| 49 | + - Copy and paste into GitHub secret |
| 50 | + |
| 51 | +2. **CLOUDFLARE_ACCOUNT_ID** |
| 52 | + - Find at https://dash.cloudflare.com |
| 53 | + - Look in the URL or Workers & Pages section |
| 54 | + - Copy your Account ID |
| 55 | + |
| 56 | +#### Configure Worker Secrets |
| 57 | + |
| 58 | +Set environment variables in Cloudflare: |
| 59 | + |
| 60 | +```bash |
| 61 | +# Using Wrangler CLI locally |
| 62 | +wrangler secret put PERSONAL_EMAIL |
| 63 | +wrangler secret put WORK_EMAIL |
| 64 | +wrangler secret put MAILCHANNELS_API_KEY |
| 65 | +wrangler secret put PINCODE |
| 66 | +wrangler secret put FROM_EMAIL |
| 67 | +wrangler secret put FROM_NAME |
| 68 | +``` |
| 69 | + |
| 70 | +Or set them in the Cloudflare Dashboard: |
| 71 | +- Go to Workers & Pages → mailrelay → Settings → Variables |
| 72 | +- Add each secret |
| 73 | + |
| 74 | +#### Deploy |
| 75 | + |
| 76 | +Push to `main` branch: |
| 77 | + |
| 78 | +```bash |
| 79 | +git push origin main |
| 80 | +``` |
| 81 | + |
| 82 | +GitHub Actions will automatically deploy to Cloudflare Workers. |
| 83 | + |
| 84 | +### Option 2: Manual Deployment |
| 85 | + |
| 86 | +```bash |
| 87 | +# Build and deploy |
| 88 | +npm run deploy |
| 89 | +``` |
| 90 | + |
| 91 | +## MailChannels Setup |
| 92 | + |
| 93 | +MailRelay uses MailChannels for email delivery. You need: |
| 94 | + |
| 95 | +1. **Domain with SPF/DKIM configured** for MailChannels |
| 96 | +2. **MailChannels API access** (free for Cloudflare Workers users) |
| 97 | + |
| 98 | +See: https://blog.cloudflare.com/sending-email-from-workers-with-mailchannels/ |
| 99 | + |
| 100 | +## Verification |
| 101 | + |
| 102 | +After deployment: |
| 103 | + |
| 104 | +1. Visit your worker URL (e.g., `https://mailrelay.<your-subdomain>.workers.dev`) |
| 105 | +2. You should see "Deployment Test Successful" |
| 106 | +3. Test sending an email through the form |
| 107 | + |
| 108 | +## Troubleshooting |
| 109 | + |
| 110 | +### Deployment fails |
| 111 | + |
| 112 | +- Check GitHub Actions logs |
| 113 | +- Verify CLOUDFLARE_API_TOKEN has correct permissions |
| 114 | +- Verify CLOUDFLARE_ACCOUNT_ID is correct |
| 115 | + |
| 116 | +### Worker runs but emails don't send |
| 117 | + |
| 118 | +- Check MailChannels API key is set correctly |
| 119 | +- Verify domain SPF/DKIM records |
| 120 | +- Check worker logs in Cloudflare Dashboard |
| 121 | + |
| 122 | +### Local development issues |
| 123 | + |
| 124 | +- Ensure `.dev.vars` file exists with all required variables |
| 125 | +- Run `wrangler login` if authentication fails |
0 commit comments