The project is in a healthy, maintained state
A Ruby client and Rails integration for Cloudflare's Email Service. Send mail via an ActionMailer delivery method, receive mail via an ActionMailbox ingress backed by a shipped Cloudflare Email Worker template.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Development

~> 5.20
~> 2.1
~> 13.0
~> 3.20
>= 2.0, < 3.0
>= 7.2.3.2, < 9.0

Runtime

>= 0.2, < 1.0
~> 0.1.1
 Project Readme

Cloudflare Email

Send and receive email in Ruby and Rails through Cloudflare Email Service.

Use your existing Rails mailers, receive messages through Action Mailbox, and add persistent inboxes with Mailbox Kit. SQLite is supported. Database tenancy and the management UI are optional.

Install

gem "cloudflare-email", "~> 0.4.0"

Mailbox Kit installs automatically. If you use another email provider, you can use Mailbox Kit on its own.

Requires Ruby 3.2+; Rails integrations support Rails 7.2–8.1. Use a current patch release. Plain Ruby sending does not require Rails or a database.

Send from Rails

bundle install
bin/rails generate cloudflare:email:install --no-inbound

Verify a sending domain in Cloudflare and add your account ID and sending token:

export CLOUDFLARE_ACCOUNT_ID=your-account-id
export CLOUDFLARE_API_TOKEN=your-email-sending-token

Your regular mailers can now send through Cloudflare:

class HelloMailer < ApplicationMailer
  def hello(address)
    mail(from: "hello@mail.example.com", to: address, subject: "Hello") do |format|
      format.text { render plain: "Hello from Rails!" }
    end
  end
end

HelloMailer.hello("you@example.net").deliver_now

HTML templates, attachments, multipart messages, cc/bcc, and reply headers work through Action Mailer. Follow the Rails setup guide for receiving and delivery tracking.

Receive email

The included Worker stores incoming email at Cloudflare and retries delivery while Rails is unavailable. Rails verifies each request and stores the original email through Action Mailbox.

Deploy to Cloudflare

Prepare Rails and deploy the Worker, then connect your receiving address in Cloudflare Email Routing.

Build an inbox

The mailbox guide walks through creating inboxes and aliases, receiving mail, marking it read, archiving it, and sending replies.

Mount the optional management UI to manage mailboxes and read messages using your app's login and permissions. It is server-rendered and needs no frontend build.

For a runnable SQLite example, clone the hello-world Rails app.

Plain Ruby

require "cloudflare-email"

client = Cloudflare::Email::Client.new(
  account_id: ENV.fetch("CLOUDFLARE_ACCOUNT_ID"),
  api_token: ENV.fetch("CLOUDFLARE_API_TOKEN"),
)

response = client.send(
  from: "hello@mail.example.com",
  to: "you@example.net",
  subject: "Hello",
  text: "Hello from Ruby!",
)
response.message_id
response.accepted?

Acceptance is the start of delivery. Use delivery events to track delivered messages, bounces, and complaints. See the Ruby API reference for attachments, raw MIME, and configuration.

Guides

Task Guide
Set up sending, receiving, and tracking Rails quickstart
Explore the available features Feature list
Create inboxes and aliases Mailboxes
Add mailbox administration Management UI
Configure addresses and customer subdomains Cloudflare domain setup
Save outgoing messages and safely retry jobs Outbox
Track delivery and bounces Delivery events
Use separate SQLite databases Database tenancy
Connect a custom receiving endpoint Custom ingress
Diagnose missing mail Troubleshooting
Configure the client and command-line tasks Reference

Security · Contributing · MIT license