Skip to content
Product

MailChannels Enables Free Email Sending for Cloudflare Workers Customers

By Ken Simpson | 5 minute read

San Francisco, March 2nd, 2022 –Today, MailChannels, the only transactional email service that automatically blocks spam and phishing, is launching a free email sending service for Cloudflare Workers. The new service enables Cloudflare developers to send email messages from within their Workers apps, with no authentication or domain verification required.

Cloudflare Workers is a serverless software hosting platform that allows developers to create applications that run entirely on Cloudflare’s extensive global network. Until now, developers had to set up an account with an external transactional email service, verify their domain, and then go through a warm-up process before sending any significant volume of email.

“Cloudflare Workers is a fantastic platform for developers and as a very old and happy Cloudflare customer ourselves, we wanted to find a way to help Workers succeed,” said Ken Simpson, MailChannels CEO and co-founder. “We want to make email sending as painless as possible for developers, which is something we’ve been doing for the past decade in the web hosting space.”

With MailChannels, developers can start sending right away, without the need for time-consuming account setup. MailChannels makes this possible through automated anti-abuse technology that detects spam, phishing, and other forms of harmful email. Over 650 web hosting providers use the MailChannels service to send email from tens of millions of hosting end-users across tens of thousands of web hosting servers worldwide. This same powerful capability is now available to all Cloudflare customers.

MailChannels sends email on behalf of more domains than any other transactional email service, with 43% global market share as measured by Builtwith.com. Extensive anti-abuse capabilities detect spam and phishing automatically, rate limiting and blocking suspicious emails and senders to ensure the delivery of legitimate emails, automatically.

Getting Started

You can cut and paste the code below to create a Worker handler that will send an email message using MailChannels when the “Send” button is clicked on the web form.

addEventListener("fetch", event => {

    event.respondWith(handleRequest(event.request))

})

 

async function handleRequest(request) {

    let content = "";

    for( var i of request.headers.entries() ) {

        content += i[0] + ": " + i[1] + "n";

    }

    let send_request = new Request("https://api.mailchannels.net/tx/v1/send", {

        "method": "POST",

        "headers": {

            "content-type": "application/json",

        },

        "body": JSON.stringify({

            "personalizations": [

                { "to": [ {"email": "test@example.com",

                        "name": "Test Recipient"}]}

            ],

            "from": {

                "email": "sender@example.com",

                "name": "Test Sender",

            },

            "subject": "Test Subject",

            "content": [{

                "type": "text/plain",

                "value": "Test message contentnn" + content,

            }],

        }),

    });

 

    let respContent = "";

    // only send the mail on "POST", to avoid spiders, etc.

    if( request.method == "POST" ) {

        const resp = await fetch(send_request);

        const respText = await resp.text();

 

        respContent = resp.status + " " + resp.statusText + "nn" + respText;

 

    }

 

    let htmlContent = "<html><head></head><body><pre>" +

        "</pre><p>Click to send message: <form method="post"><input type="submit" value="Send"/></form></p>" +

        "<pre>" + respContent + "</pre>" +

        "</body></html>";

    return new Response(htmlContent, {

        headers: { "content-type": "text/html" },

    })

}

For more information, please see our knowledge base article.

Disclaimer

Cloudflare does not have any involvement in the MailChannels service and did not review or approve of this blog post. Use of the MailChannels API to send email is governed by our Terms of Service.

Cut your support tickets and make customers happier