Code Monkey home page Code Monkey logo

mail's Introduction

Cloudflare + MailChannels Email Sending with DKIM

MailChannels allows free email sending using a Cloudflare Worker. This code adapts the example provided in the article to implement DKIM signing. Official documentation on how to sign messages with DKIM is available here.

Setup

Before you start, make sure to set up Wrangler as explained here.

We'll need to generate keys and a DNS record, which we can do with the steps in this tutorial.

Generate the Private Key

To generate a private key and upload it to the worker, run the following command:

openssl genrsa 2048 | tee priv_key.pem | openssl rsa -outform der | openssl base64 -A | wrangler secret put DKIM_PRIVATE_KEY

The parts of this command:

openssl genrsa 2048 generates a 2048-bit RSA key. The output is passed to

tee priv_key.pem, which writes the key to the priv_key.pem file, and passes the key to

openssl rsa -outform der | openssl base 64 -A, which converts the key from PEM format to DER format, then base64 encodes it (this essentially removes the header from the PEM formatted key). The output is finally passed to

wrangler secret put DKIM_PRIVATE_KEY, which adds it as a secret to our Cloudflare Worker.

Create the DNS Record

Now, we need to add the public key to a TXT record. Run the following command:

echo -n "v=DKIM1;p=" > record.txt && openssl rsa -in priv_key.pem -pubout -outform der | openssl base64 -A >> record.txt

This creates a public key from the private key (openssl rsa -in priv_key.pem -pubout -outform der), encodes it in base64 (openssl base 64 -A), and finally writes it to the record.txt file.

Copy the contents of the record.txt file and add it as a TXT record to your domain. Adding the TXT record

Updating the Code

Find these lines in src/index.ts:

            to: [
              {
                email: "", // add your to email here
              },
            ],
            dkim_domain: "", // add your domain
        from: {
          email: "", // add your from email here
        },

and add in your to and from email addresses, as well as the domain you are sending from.

Running

Run wrangler dev or wrangler publish, and you should be able to test it out!

mail's People

Contributors

maggie-j-liu avatar ttulttul avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

mail's Issues

Have you tested this?

Please refer this to test dkim is setup properly or not.
For me it's not working( i.e not showing DKIM pass)

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.