Skip to content

This is a simple proxy server that can be used for sending free transactional emails through Cloudflare workers.

License

Notifications You must be signed in to change notification settings

testbook/webengage-cloudflare-mailchannel

 
 

Repository files navigation

Cloudflare Worker Email Server

Cloudflare Worker Email Server

Send free transactional emails from your Cloudflare Workers using MailChannels.

Getting Started!

  1. Clone this repository
  2. Install the dependencies with npm install
  3. Use the command npx wrangler secret put --env production TOKEN to deploy a securely stored token to Cloudflare. With this command, you will be prompted to enter a random secret value, which will be used to authenticate your requests with the HTTP Authorization header as described below. You can also set this encrypted value directly in your Cloudflare dashboard.
  4. Deploy the worker with npm run deploy

Or deploy directly to cloudflare

Deploy to Cloudflare Workers

Setup SPF

SPF is a DNS record that helps prevent email spoofing. You will need to add an SPF record to your domain to allow MailChannels to send emails on your behalf.

  1. Add a TXT record to your domain with the following values:
    • Name: @
    • Value: v=spf1 a mx include:relay.mailchannels.net ~all

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.

Usage

Once you have deployed this worker function to Cloudflare Workers, you can send emails by making a POST request to the worker on the /api/email endpoint with the following parameters:

  • Note you need to pass an Authorization header with the secure token you deployed. Like the following: Authorization: TOKEN

Request Body

Your api/email request payload should be structured as follows:

{
  "email": {
    "from": "[email protected]",
    "fromName": "John Doe",
    "replyTo": [
      "[email protected]",
      "[email protected]"
    ],
    "subject": "email subject",
    "text": "text body",
    "html": "html body",
    "recipients": {
      "to": [
        {
          "name": "Recipient1",
          "email": "abc12345"
        },
        {
          "name": "Recipient2",
          "email": "[email protected]"
        }
      ],
      "cc": [
        "[email protected]",
        "[email protected]"
      ],
      "bcc": [
        "[email protected]",
        "[email protected]"
      ]
    }
  },
  "metadata": {
    "campaignType": "PROMOTIONAL",
    "custom": {
      "key1": "val1",
      "key2": "val2"
    },
    "timestamp": 1521012814,
    "messageId": "message-id"
  },
  "version": "1.0"
}

About

This is a simple proxy server that can be used for sending free transactional emails through Cloudflare workers.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 100.0%