Skip to content

A Cloudflare Workers project that leverages Cloudflare Email Routing, allowing you to send information to your email via API calls.

Notifications You must be signed in to change notification settings

WongSaang/CF-Postal-Worker

Repository files navigation

CF Postal Worker

This is a project using Cloudflare Workers and leveraging Cloudflare 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

or

  1. Follow the instructions in 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:

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.
  1. Deploy to Cloudflare Workers:
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

fetch('https://example.workers.dev/send', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    subject: 'Email subject',
    body: '<h1>Email content</h1>'
  })
})

Acknowledgments

License

Distributed under the MIT License. See LICENSE for more information.

About

A Cloudflare Workers project that leverages Cloudflare Email Routing, allowing you to send information to your email via API calls.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published