Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/wongsaang/cf-postal-worker
A Cloudflare Workers project that leverages Cloudflare Email Routing, allowing you to send information to your email via API calls.
https://github.com/wongsaang/cf-postal-worker
cloudflare-workers email-routing
Last synced: about 2 months ago
JSON representation
A Cloudflare Workers project that leverages Cloudflare Email Routing, allowing you to send information to your email via API calls.
- Host: GitHub
- URL: https://github.com/wongsaang/cf-postal-worker
- Owner: WongSaang
- Created: 2023-10-29T01:42:43.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2023-11-02T08:48:44.000Z (about 1 year ago)
- Last Synced: 2023-11-02T09:39:57.506Z (about 1 year ago)
- Topics: cloudflare-workers, email-routing
- Language: TypeScript
- Homepage:
- Size: 47.9 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# CF Postal Worker
This is a project using [Cloudflare Workers](https://workers.cloudflare.com/) and leveraging [Cloudflare Email Routing](https://developers.cloudflare.com/email-routing/) to enable you to send information to your email by calling the Worker's API. You don't need an email server or third-party email forwarding services, and you don't have to maintain a database or develop a backend.
Use cases:
- If you have a static web project and don't want to develop a backend or manage a database, you can integrate a contact form and directly send the information to your email.
- Other scenarios that require forwarding messages to an email.## Prerequisites
- A Cloudflare account
- A domain name (you can register the cheapest domain on Cloudflare)
- If deploying via the command line, you need to have Node.js environment installed locally.## Deployment
[![Deploy to Cloudflare Workers](https://deploy.workers.cloudflare.com/button)](https://deploy.workers.cloudflare.com/?url=https://github.com/WongSaang/CF-Postal-Worker)
or
1. Follow the instructions in [Enable Email Routing](https://developers.cloudflare.com/email-routing/get-started/enable-email-routing/) to enable Email Routing.
2. Clone or download this project.
3. Rename the file "wrangler.toml.example" to "wrangler.toml" and set the following environment variables:
```toml
SENDER_ADDRESS = "[email protected]" # Set it to the email address you configured in Email Routing
SENDER_NAME = "Sender" # Sender's name
RECIPIENT_ADDRESS = "[email protected]" # Set it to your recipient email address
ALLOWED_ORIGINS = "https://example.com" # The domain name of the site allowed to call the API, multiple domain names are separated by commas, "*" means all domain names are allowed.
```4. Deploy to Cloudflare Workers:
```bash
npm install
npm run deploy
```## API
| Endpoint | Method | Parameters | Description |
|-----------|--------|--------------------|---------------------------|
| /send | POST | - subject Email subject
- body Email content, can be an HTML string | Send an email |### Example
```js
fetch('https://example.workers.dev/send', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
subject: 'Email subject',
body: 'Email content
'
})
})
```## Acknowledgments
- [Cloudflare](https://www.cloudflare.com/)
- [Hono](https://hono.dev/), this project is developed based on this framework## License
Distributed under the MIT License. See [LICENSE](LICENSE) for more information.