testin email

This commit is contained in:
miles committed 2026-04-09 22:03:59 -05:00
1 parent 7b0fc6c7ad
commit b53ab78028
46 files changed
+351607 -17

No files matched your search

+62
View File
@@ -0,0 +1,62 @@
# FEDL Email Worker
Handles incoming emails and can send emails using Cloudflare Workers Email.
## Setup
### 1. Configure Email Routing (Cloudflare Dashboard)
1. Go to **Email** → **Email Routing** in Cloudflare Dashboard
2. Select your domain **fedl.site**
3. Add an email address: `[email protected]`
4. Create a routing rule:
- **When**: A message is sent to `[email protected]`
- **Then**: Route to **Worker** → `fedl-email-worker`
### 2. Deploy the Worker
```bash
cd worker
npm install
npx wrangler deploy
```
### 3. Configure Worker Bindings
In `wrangler.jsonc`, add:
```json
{
"name": "fedl-email-worker",
"main": "src/index.ts",
"compatibility_date": "2024-01-01",
"vars": {
"FORWARD_TO": "[email protected]"
}
}
```
### 4. Environment Variables
| Variable | Purpose |
|----------|---------|
| `FORWARD_TO` | Email address to forward incoming emails to |
| `SEND_EMAIL` | Cloudflare Email binding (auto-configured) |
## API Endpoints
### Send Email
```
POST /send
Content-Type: application/json
{
"to": "[email protected]",
"subject": "Password Reset",
"text": "Click here to reset: ..."
}
```
### Update wrangler.jsonc for Cloudflare Pages/Workers
Make sure your `wrangler.jsonc` has the email binding configured in the Cloudflare dashboard under Workers & Pages → your worker → Settings → Variables.
+6
View File
@@ -0,0 +1,6 @@
{
"account": {
"id": "b383c4fd325135e56323d694db7a06d3",
"name": "[email protected]'s Account"
}
}
+15
View File
@@ -0,0 +1,15 @@
{
"name": "fedl-email-worker",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"node_modules/@cloudflare/workers-types": {
"version": "4.20260410.1",
"resolved": "https://registry.npmjs.org/@cloudflare/workers-types/-/workers-types-4.20260410.1.tgz",
"integrity": "sha512-dPZT4aXxwhGHFhWA9iZhWVfFoO8g9exiLzeaS8y43Dw0Sard6Gb3o5LJjReav3ejHbQLHUfGEiZsRPGW8qmgMg==",
"dev": true,
"license": "MIT OR Apache-2.0"
}
}
}
+14482
View File
File diff suppressed because it is too large. Load diff
+14430
View File
File diff suppressed because it is too large. Load diff
+14549
View File
File diff suppressed because it is too large. Load diff
+14497
View File
File diff suppressed because it is too large. Load diff
+14557
View File
File diff suppressed because it is too large. Load diff
+14505
View File
File diff suppressed because it is too large. Load diff
+14558
View File
File diff suppressed because it is too large. Load diff
+14506
View File
File diff suppressed because it is too large. Load diff
+14578
View File
File diff suppressed because it is too large. Load diff
+14526
View File
File diff suppressed because it is too large. Load diff
+14583
View File
File diff suppressed because it is too large. Load diff
+14531
View File
File diff suppressed because it is too large. Load diff
+14589
View File
File diff suppressed because it is too large. Load diff
+14537
View File
File diff suppressed because it is too large. Load diff
+14589
View File
File diff suppressed because it is too large. Load diff
+14537
View File
File diff suppressed because it is too large. Load diff
+135
View File
@@ -0,0 +1,135 @@
# Cloudflare Workers Types
> **Note**
>
> We now recommend using the [Wrangler CLI](https://www.npmjs.com/package/wrangler) and the `wrangler types` command to generate types based on your compatibility date _and_ compatibility flags. You can learn more about this, and how to migrate from @cloudflare/workers-types [here in our docs](https://developers.cloudflare.com/workers/languages/typescript/#generate-types).
>
> @cloudflare/workers-types will continue to be published on the same schedule.
## Install
```bash
npm install -D @cloudflare/workers-types
-- Or
yarn add -D @cloudflare/workers-types
```
## Usage
The following is a minimal `tsconfig.json` for use alongside this package:
**`tsconfig.json`**
```json
{
"compilerOptions": {
"target": "esnext",
"module": "esnext",
"lib": ["esnext"],
"types": ["@cloudflare/workers-types"]
}
}
```
### Compatibility dates
![Entrypoints for compatibility dates](./npm/workers-types/entrypoints.svg)
The Cloudflare Workers runtime manages backwards compatibility through the use of [Compatibility Dates](https://developers.cloudflare.com/workers/platform/compatibility-dates/). Using different compatibility dates affects the runtime types available to your Worker, and so it's important you specify the correct entrypoint to the `workers-types` package to match your compatibility date (which is usually set in your `wrangler.toml` configuration file). `workers-types` currently exposes the following entrypoints to choose from:
- `@cloudflare/workers-types`
The default entrypoint exposes the runtime types for a compatibility date before `2021-11-03`.
- `@cloudflare/workers-types/2021-11-03`
This entrypoint exposes the runtime types for a compatibility date between `2021-11-03` and `2022-01-31`.
- `@cloudflare/workers-types/2022-01-31`
This entrypoint exposes the runtime types for a compatibility date between `2022-01-31` and `2022-03-21`.
- `@cloudflare/workers-types/2022-03-21`
This entrypoint exposes the runtime types for a compatibility date between `2022-03-21` and `2022-08-04`.
- `@cloudflare/workers-types/2022-08-04`
This entrypoint exposes the runtime types for a compatibility date between `2022-08-04` and `2022-10-31`.
- `@cloudflare/workers-types/2022-10-31`
This entrypoint exposes the runtime types for a compatibility date between `2022-10-31` and `2022-11-30`.
- `@cloudflare/workers-types/2022-11-30`
This entrypoint exposes the runtime types for a compatibility date between `2022-11-30` and `2023-03-01`.
- `@cloudflare/workers-types/2023-03-01`
This entrypoint exposes the runtime types for a compatibility date between `2023-03-01` and `2023-07-01`.
- `@cloudflare/workers-types/2023-07-01`
This entrypoint exposes the runtime types for a compatibility date after `2023-07-01`.
- `@cloudflare/workers-types/experimental`
This entrypoint exposes the runtime types for the latest compatibility date. The types exposed by this entrypoint will change over time to always reflect the latest version of the Workers runtime.
To use one of these entrypoints, you need to specify them in your `tsconfig.json`. For example, this is a sample `tsconfig.json` for using the `2022-08-04` entrypoint.
```json
{
"compilerOptions": {
"target": "esnext",
"module": "esnext",
"lib": ["esnext"],
"types": ["@cloudflare/workers-types/2022-08-04"]
}
}
```
### Importable Types
It's not always possible (or desirable) to modify the `tsconfig.json` settings for a project to include all the Cloudflare Workers types. For use cases like that, this package provides importable versions of its types, which are usable with no additional `tsconfig.json` setup. For example:
```ts
import type { Request as WorkerRequest, ExecutionContext } from "@cloudflare/workers-types/experimental"
export default {
fetch(request: WorkerRequest, env: unknown, ctx: ExecutionContext) {
return new Response("OK")
}
}
```
### Using bindings
It's recommended that you create a type file for any bindings your Worker uses. Create a file named
`worker-configuration.d.ts` in your src directory.
If you're using Module Workers, it should look like this:
```typescript
// worker-configuration.d.ts
interface Env {
MY_ENV_VAR: string;
MY_SECRET: string;
myKVNamespace: KVNamespace;
}
```
For Service Workers, it should augment the global scope:
```typescript
// worker-configuration.d.ts
declare global {
const MY_ENV_VAR: string;
const MY_SECRET: string;
const myKVNamespace: KVNamespace;
}
export {}
```
Wrangler can also generate this for you automatically from your `wrangler.toml` configuration file, using the `wrangler types` command.
+53
View File
@@ -0,0 +1,53 @@
<?xml version="1.0" encoding="utf-8"?>
<svg viewBox="0 0 540 280" width="540px" height="280px" xmlns="http://www.w3.org/2000/svg">
<rect width="540" height="280" style="fill: rgb(255, 255, 255);"/>
<g transform="matrix(1, 0, 0, 1, 61.018997, -319.418854)">
<rect x="128.981" y="349.42" width="340" height="30" style="fill: rgb(238, 238, 238);"/>
<text style="font-family: monospace; font-size: 14px; white-space: pre;" x="135.709" y="369.298">@cloudflare/workers-types</text>
</g>
<g transform="matrix(1, 0, 0, 1, 61.018997, -289.418793)">
<rect x="128.981" y="349.42" width="340" height="30" style="fill: rgb(221, 221, 221);"/>
<text style="font-family: monospace; font-size: 14px; white-space: pre;"><tspan x="135.709" y="369.298">@cloudflare/workers-types/</tspan><tspan style="fill: rgb(0, 85, 220); font-weight: 700;">2021-11-03</tspan></text>
</g>
<g transform="matrix(1, 0, 0, 1, 61.018997, -259.418793)">
<rect x="128.981" y="349.42" width="340" height="30" style="fill: rgb(238, 238, 238);"/>
<text style="font-family: monospace; font-size: 14px; white-space: pre;"><tspan x="135.709" y="369.298">@cloudflare/workers-types/</tspan><tspan style="fill: rgb(0, 54, 130); font-weight: 700;">2022-01-31</tspan></text>
</g>
<g transform="matrix(1, 0, 0, 1, 61.018997, -229.418869)">
<rect x="128.981" y="349.42" width="340" height="30" style="fill: rgb(221, 221, 221);"/>
<text style="font-family: monospace; font-size: 14px; white-space: pre;"><tspan x="135.709" y="369.298">@cloudflare/workers-types/</tspan><tspan style="fill: rgb(0, 85, 220); font-weight: 700;">2022-03-21</tspan></text>
</g>
<g transform="matrix(1, 0, 0, 1, 61.018997, -199.418839)">
<rect x="128.981" y="349.42" width="340" height="30" style="fill: rgb(238, 238, 238);"/>
<text style="font-family: monospace; font-size: 14px; white-space: pre;"><tspan x="135.709" y="369.298">@cloudflare/workers-types/</tspan><tspan style="fill: rgb(0, 54, 130); font-weight: 700;">2022-08-04</tspan></text>
</g>
<g transform="matrix(1, 0, 0, 1, 61.018997, -169.418839)">
<rect x="128.981" y="349.42" width="340" height="30" style="fill: rgb(221, 221, 221);"/>
<text style="font-family: monospace; font-size: 14px; white-space: pre;"><tspan x="135.709" y="369.298">@cloudflare/workers-types/</tspan><tspan style="fill: rgb(0, 85, 220); font-weight: 700;">2022-10-31</tspan></text>
</g>
<g transform="matrix(1, 0, 0, 1, 61.017925, -139.418854)">
<rect x="128.981" y="349.42" width="340" height="30" style="fill: rgb(238, 238, 238);"/>
<text style="font-family: monospace; font-size: 14px; white-space: pre;"><tspan x="135.709" y="369.298">@cloudflare/workers-types/</tspan><tspan style="fill: rgb(0, 54, 130); font-weight: 700;">2022-11-30</tspan></text>
</g>
<g transform="matrix(1, 0, 0, 1, 61.017925, -109.418816)">
<rect x="128.981" y="349.42" width="340" height="30" style="fill: rgb(221, 221, 221);"/>
<text style="font-family: monospace; font-size: 14px; white-space: pre;" x="135.709" y="369.298">@cloudflare/workers-types/experimental</text>
</g>
<line style="fill: rgb(216, 216, 216); stroke: rgb(0, 0, 0);" x1="160" y1="60" x2="190" y2="60"/>
<line style="fill: rgb(216, 216, 216); stroke: rgb(0, 0, 0);" x1="160" y1="90" x2="190" y2="90"/>
<line style="fill: rgb(216, 216, 216); stroke: rgb(0, 0, 0);" x1="160" y1="120" x2="190" y2="120"/>
<line style="fill: rgb(216, 216, 216); stroke: rgb(0, 0, 0);" x1="160" y1="150" x2="190" y2="150"/>
<line style="fill: rgb(216, 216, 216); stroke: rgb(0, 0, 0);" x1="160" y1="180" x2="190" y2="180"/>
<line style="fill: rgb(216, 216, 216); stroke: rgb(0, 0, 0);" x1="160" y1="210" x2="190" y2="210"/>
<line style="fill: rgb(216, 216, 216); stroke: rgb(0, 0, 0);" x1="175" y1="60" x2="175" y2="240"/>
<line style="fill: rgb(216, 216, 216); stroke: rgb(0, 0, 0); stroke-dasharray: 2px;" x1="175" y1="30" x2="175" y2="60"/>
<line style="fill: rgb(216, 216, 216); stroke: rgb(0, 0, 0); stroke-dasharray: 2px;" x1="175" y1="240" x2="175" y2="270"/>
<text style="fill: rgb(51, 51, 51); font-family: monospace; font-size: 14px; font-weight: 700; text-anchor: middle; white-space: pre;" transform="matrix(1, 0, 0, 1, 307.347992, -77.253761)"><tspan x="52.652" y="98.052">types Entrypoint</tspan></text>
<text style="fill: rgb(51, 51, 51); font-family: monospace; font-size: 14px; font-weight: 700; text-anchor: end; white-space: pre;" x="157.185" y="20.798">compatibility_date</text>
<text style="fill: rgb(0, 85, 220); font-family: monospace; font-size: 14px; font-weight: 700; text-anchor: end; white-space: pre;" x="153.994" y="64.798">2021-11-03</text>
<text style="fill: rgb(0, 54, 130); font-family: monospace; font-size: 14px; font-weight: 700; text-anchor: end; white-space: pre;" x="153.994" y="94.798">2022-01-31</text>
<text style="fill: rgb(0, 85, 220); font-family: monospace; font-size: 14px; font-weight: 700; text-anchor: end; white-space: pre;" x="153.994" y="124.798">2022-03-21</text>
<text style="fill: rgb(0, 54, 130); font-family: monospace; font-size: 14px; font-weight: 700; text-anchor: end; white-space: pre;" x="153.994" y="154.798">2022-08-04</text>
<text style="fill: rgb(0, 85, 220); font-family: monospace; font-size: 14px; font-weight: 700; text-anchor: end; white-space: pre;" x="153.994" y="184.798">2022-10-31</text>
<text style="fill: rgb(0, 54, 130); font-family: monospace; font-size: 14px; font-weight: 700; text-anchor: end; white-space: pre;" x="153.994" y="214.798">2022-11-30</text>
</svg>

After

Width:  |  Height:  |  Size: 5.4 KiB

File diff suppressed because it is too large. Load diff
+15262
View File
File diff suppressed because it is too large. Load diff
+14482
View File
File diff suppressed because it is too large. Load diff
+14430
View File
File diff suppressed because it is too large. Load diff
+14622
View File
File diff suppressed because it is too large. Load diff
+14570
View File
File diff suppressed because it is too large. Load diff
+14482
View File
File diff suppressed because it is too large. Load diff
+14430
View File
File diff suppressed because it is too large. Load diff
+11
View File
@@ -0,0 +1,11 @@
{
"name": "@cloudflare/workers-types",
"description": "TypeScript typings for Cloudflare Workers",
"repository": {
"type": "git",
"url": "https://github.com/cloudflare/workerd"
},
"author": "Cloudflare Workers DevProd Team <[email protected]> (https://workers.cloudflare.com)",
"license": "MIT OR Apache-2.0",
"version": "4.20260410.1"
}
+22
View File
@@ -0,0 +1,22 @@
{
"name": "fedl-email-worker",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "fedl-email-worker",
"version": "1.0.0",
"devDependencies": {
"@cloudflare/workers-types": "^4.20241127.0"
}
},
"node_modules/@cloudflare/workers-types": {
"version": "4.20260410.1",
"resolved": "https://registry.npmjs.org/@cloudflare/workers-types/-/workers-types-4.20260410.1.tgz",
"integrity": "sha512-dPZT4aXxwhGHFhWA9iZhWVfFoO8g9exiLzeaS8y43Dw0Sard6Gb3o5LJjReav3ejHbQLHUfGEiZsRPGW8qmgMg==",
"dev": true,
"license": "MIT OR Apache-2.0"
}
}
}
+8
View File
@@ -0,0 +1,8 @@
{
"name": "fedl-email-worker",
"version": "1.0.0",
"private": true,
"devDependencies": {
"@cloudflare/workers-types": "^4.20241127.0"
}
}
+3
View File
@@ -0,0 +1,3 @@
export interface Env {
FORWARD_TO: string;
}
+60
View File
@@ -0,0 +1,60 @@
export default {
async email(message, env, ctx) {
const subject = message.headers.get('subject') || 'No Subject';
const from = message.from;
const to = message.to;
console.log(`[FEDL Email] Received email from: ${from}, to: ${to}, subject: ${subject}`);
const forwardedAddress = env.FORWARD_TO || '';
if (forwardedAddress) {
await message.forward(forwardedAddress);
console.log(`[FEDL Email] Forwarded to: ${forwardedAddress}`);
} else {
console.log(`[FEDL Email] No forwarding address configured (FORWARD_TO not set)`);
}
},
async fetch(request: Request, env: Env): Promise<Response> {
const url = new URL(request.url);
if (url.pathname === '/send' && request.method === 'POST') {
const body = await request.json() as { to: string; subject: string; text: string };
if (!body.to || !body.subject || !body.text) {
return new Response(JSON.stringify({ error: 'Missing to, subject, or text' }), {
status: 400,
headers: { 'Content-Type': 'application/json' }
});
}
try {
await env.SEND_EMAIL.send({
from: `FEDL <[email protected]>`,
to: body.to,
subject: body.subject,
text: body.text,
});
return new Response(JSON.stringify({ ok: true }), {
status: 200,
headers: { 'Content-Type': 'application/json' }
});
} catch (error: any) {
console.error(`[FEDL Email] Send failed: ${error.message}`);
return new Response(JSON.stringify({ error: error.message }), {
status: 500,
headers: { 'Content-Type': 'application/json' }
});
}
}
return new Response('FEDL Email Worker\n', { status: 200 });
}
} satisfies ExportedHandler<Env>;
interface Env {
SEND_EMAIL: any;
FORWARD_TO: string;
}
+5
View File
@@ -0,0 +1,5 @@
{
"name": "fedl-email-worker",
"main": "src/index.ts",
"compatibility_date": "2024-01-01"
}
+6
View File
@@ -0,0 +1,6 @@
name = "fedl-email-worker"
main = "src/index.ts"
compatibility_date = "2024-01-01"
[vars]
FORWARD_TO = ""