Giter Site home page Giter Site logo

mcansh / cloudflare-email Goto Github PK

View Code? Open in Web Editor NEW

This project forked from sh4yy/cloudflare-email

0.0 1.0 0.0 27 KB

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

License: MIT License

TypeScript 100.00%

cloudflare-email's Introduction

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. Add a random TOKEN to the wrangler.toml file (this will be used to authenticate your requests)
  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 TOKEN you set in the wrangler.toml file. Like the following: Authorization: TOKEN

Basic Email

The Most basic request would look like this:

{
	"to": "[email protected]",
	"from": "[email protected]",
	"subject": "Hello World",
	"text": "Hello World"
}

HTML Emails

You can also send HTML emails by adding an html parameter to the request. This can be used in conjunction with the text parameter to send a multi-part email.

{
	"to": "[email protected]",
	"from": "[email protected]",
	"subject": "Hello World",
	"html": "<h1>Hello World</h1>"
}

Sender and Recipient Name

You can also specify a sender and recipient name by adding a name parameter to the request. This can be used for both the to and from parameters.

{
	"to": { "email": "[email protected]",  "name": "John Doe" },
	"from": { "email": "[email protected]", "name": "Jane Doe" },
	"subject": "Hello World",
	"text": "Hello World"
}

Sending to Multiple Recipients

You may also send to multiple recipients by passing an array of eamils, or an array of objects with email and name properties.

{
	"to": [
		"[email protected]",
		"[email protected]"
 	],
	"from": "[email protected]",
	"subject": "Hello World",
	"text": "Hello World"
}

or

{
	"to": [
		{ "email": "[email protected]", "name": "John Doe" },
		{ "email": "[email protected]", "name": "Rose Doe" }
 	],
	"from": "[email protected]",
	"subject": "Hello World",
	"text": "Hello World"
}

Sending BCC and CC

You can also send BCC and CC emails by passing an array of eamils, an object with email and name properties, or an array of either, similar to the to parameter.

{
	"to": "[email protected]",
	"from": "[email protected]",
	"subject": "Hello World",
	"text": "Hello World",
	"cc": [
		"[email protected]",
		"[email protected]"
	],
	"bcc": [
		"[email protected]"
	]
}

Reply To

You can also specify a reply to email address by adding a replyTo parameter to the request. Again, you can use an email string, an object with email and name properties, or an array of either.

{
	"to": "[email protected]",
	"from": "[email protected]",
	"replyTo": "[email protected]",
	"subject": "Hello World",
	"text": "Hello World"
}

cloudflare-email's People

Contributors

sh4yy avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.