Cloudflare Email Worker as a Service / API
A private api/worker service for sending email powered by Cloudflare worker project.
Prepare Job
- Prepare a domian, such as
example.com
. Now, add a website in cloudflare-dashboard and build your domain. It maybe cost you about 30min. - Select your site and domain, Enable Email Routing. It maybe cost you about 5min.
- Install warngler for delpoy cf worker. Ensure your node version >= 16.13.0 and run :
npm install wrangler@latest -g
Setup
- Get the code
git clone [email protected]:willin/cloudflare-send-email-service.git
- Deploy your worker
wrangler deploy --name send-email-worker-service
- Config DNS records
Add a TXT record to your domain with the following values:
- Name:
yourdomain.com
- Value:
v=spf1 a mx include:relay.mailchannels.net ~all
Note: If you're facing Domain Lockdown error, follow the below steps:
- Name:
_mailchannels.yourdomain.com
- Value:
v=mc1 cfid=yourdomain.workers.dev
(the value ofcfid
will also be present in the error response)
- Setup DKIM
This step is optional, but highly recommended. DKIM is a DNS record that helps prevent email spoofing. You may follow the steps listed in the MailChannels documentation to set up DKIM for your domain.
API Documentation
Endpoint
http://{{your-cf-worker-prefix}}.workers.dev/
Method
POST
Parameters
Name | Type | Description |
---|---|---|
sender_email | string | The email address of the sender. |
sender_name | string | The name of the sender. |
recipient_email | string | The email address of the recipient. |
subject | string | The subject of the email. |
message | string | The message body of the email. |
Example Request
curl -d"[email protected]&sender_name=Demo&[email protected]&subject='Hello Guy!'&msg_data='My first email sent!'" "http://your-cf-worker-prefix.workers.dev/"