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.
- 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.
or
-
Follow the instructions in Enable Email Routing to enable Email Routing.
-
Clone or download this project.
-
Rename the file "wrangler.toml.example" to "wrangler.toml" and set the following environment variables:
SENDER_ADDRESS = "sender@example.com" # Set it to the email address you configured in Email Routing
SENDER_NAME = "Sender" # Sender's name
RECIPIENT_ADDRESS = "recipient@example.com" # 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.
- Deploy to Cloudflare Workers:
npm install
npm run deploy
Endpoint | Method | Parameters | Description |
---|---|---|---|
/send | POST | - subject Email subject - body Email content, can be an HTML string |
Send an email |
fetch('https://example.workers.dev/send', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
subject: 'Email subject',
body: '<h1>Email content</h1>'
})
})
- Cloudflare
- Hono, this project is developed based on this framework
Distributed under the MIT License. See LICENSE for more information.