CloudMailin Alternative: Inbound Email to Rails With an Address per API Call
A CloudMailin alternative for Ruby and Rails: an address per API call, signed webhooks, a REST read and mail encrypted on arrival.

CloudMailin turns an email into an HTTP POST. You pick a POST format for each address, point it at a URL in your app, and the status code your app returns decides what the sending server is told. If that is how your inbound mail works today, this guide shows the same job on Mailcycle, written for a Rails app: an address your code creates per record, one signed event shape, and a read by id from a background job.
The code is Ruby, with Active Job and Active Storage, because a lot of CloudMailin targets are Rails controllers. Eight other SDKs offer every call shown here.
Every statement about CloudMailin below comes from its documentation and plans page, read on 28 November 2026. The sources table at the end lists the page for each one.
How CloudMailin hands mail to your app
A generated address or your own domain
CloudMailin’s getting started guide says an email address is generated for you when you sign up, and you give it a target URL. Its custom domain page has you add MX records for your own domain, and notes that custom domains need a paid plan.
Choosing a POST format
The HTTP POST formats page lists three current formats: Multipart Normalized, JSON Normalized and Raw Message, and recommends one of the normalized pair for new projects. JSON Normalized arrives with four parts: an envelope (with to among its fields), headers with lowercase, underscored names, the plain and html bodies, and an attachments list. Multipart Normalized carries the same fields as form parts.
What your status code tells the sender
On CloudMailin, the response is part of the SMTP conversation. The status codes page says a 2xx means the message was received and a 5xx delays it so the sending server tries again later. It also says CloudMailin does not retry the HTTP POST itself: the retry comes from the sending server.
Securing the target and storing attachments
The securing page recommends an Authorization header set per address, with any value you like, such as a bearer token. For files, the JSON format embeds each attachment as base64 content inside the POST.
One event shape, then a read by id
On Mailcycle you don’t pick a format. Every address on the account sends the same message.received event to your webhook, a JSON body with an event id, a type, a createdAt and a payload holding messageId and inboxId. Your code then asks for the message, and the gem returns it as one Ruby object with every field opened.
The split matters in practice. The webhook body stays a few hundred bytes whatever the sender attached, so it passes through Rack, a proxy or a request log without carrying a single word of the mail. The full message, attachments included, waits at its address until your job is ready for it.
An address per API call
CloudMailin users often hand out one address per account, project or ticket queue, and tell them apart afterwards. On Mailcycle, the address is a record your app creates and owns.
Provisioning from a Rails model
# config/initializers/mailcycle.rb
require "mailcycle"
MC = Mailcycle.with_api_key(
ENV.fetch("MAILCYCLE_API_KEY"),
phrase: ENV.fetch("MAILCYCLE_PHRASE")
)
# app/models/project.rb
class Project < ApplicationRecord
after_create_commit :provision_inbox
private
def provision_inbox
address = MC.addresses.create(prefix: slug, label: name, retention_days: 30)
update_columns(mailcycle_address_id: address.id, inbound_email: address.email_address)
end
end
The server adds a short random ending to prefix, so a project slug like atlas becomes an address such as atlas-k7p2@ on a shared domain. It receives mail as soon as create returns, with no DNS record to add. The label is sealed on your machine before the request is sent, so the project name travels encrypted.
Why a record beats parsing the recipient
Because the address is stored on the project, routing is one indexed lookup on mailcycle_address_id. Nothing in your app builds an address format or splits one apart, and closing a project’s inbox is MC.addresses.delete(project.mailcycle_address_id). Retention is per address too, anywhere from 1 to 90 days with 7 as the default, so a short-lived intake address and a long-lived support address can sit side by side.
Signed webhooks with your own Authorization header
A one-off task that creates the webhook
Creating a webhook needs a signed-in session, so it belongs in a task you run once per environment rather than in the web process:
# lib/tasks/mailcycle.rake
namespace :mailcycle do
desc "Create the message.received webhook for this environment"
task create_webhook: :environment do
mc = Mailcycle.sign_in(ENV.fetch("MAILCYCLE_PHRASE"))
created = mc.webhooks.create(
"https://app.example.com/inbound/mailcycle",
["message.received"],
"#{Rails.env} inbound"
)
puts "MAILCYCLE_WEBHOOK_ID=#{created.webhook.id}"
puts "MAILCYCLE_WEBHOOK_SECRET=#{created.secret}"
end
end
The secret is shown once. Put it in Rails credentials or your host’s secret store, and keep the webhook id for the replay task further down. An account holds up to 10 webhooks, each with its own URL, events and secret.
If your target already checks an Authorization header, as CloudMailin’s securing page recommends, keep that check. Choose Add a header on the webhook in the web app and Mailcycle sends your header on every delivery. The value is never returned by the API once it is set.
The Rails controller
# app/controllers/inbound_mail_controller.rb
class InboundMailController < ActionController::API
def create
raw = request.raw_post
secret = Rails.application.credentials.mailcycle_webhook_secret
unless Mailcycle.verify_webhook_signature(secret, raw, request.headers["Mailcycle-Signature"])
return head :unauthorized
end
event = JSON.parse(raw)
if event["type"] == "message.received"
InboundMailJob.perform_later(
event_id: request.headers["Mailcycle-Event-Id"],
address_id: event.dig("payload", "inboxId"),
message_id: event.dig("payload", "messageId")
)
end
head :no_content
end
end
request.raw_post is the body byte for byte as it was signed, which is what the check needs. The signature reads t=<unix seconds>,v1=<hex>, an HMAC-SHA256 of the timestamp, a full stop and the body, and the gem compares it in constant time and refuses timestamps more than five minutes from your clock. Answer with any 2xx within 10 seconds and leave the reading to the job. For deduplication, Express and FastAPI versions and local tunnels, the hub post Receive email with a webhook covers what every receiver shares.
The REST read in an Active Job
# app/jobs/inbound_mail_job.rb
class InboundMailJob < ApplicationJob
queue_as :inbound
def perform(event_id:, address_id:, message_id:)
return if ProcessedEvent.exists?(event_id: event_id)
project = Project.find_by(mailcycle_address_id: address_id)
message = MC.messages.get(message_id)
item = (project || Project.unrouted).inbound_items.create!(
subject: message.subject,
body: message.text,
html: message.safe_html,
sender: message.from_address,
sender_name: message.from_name,
reply_to: message.reply_to,
source_message_id: message.message_id
)
message.attachments.each do |file|
data = MC.messages.attachment(message, file.index)
item.files.attach(io: StringIO.new(data), filename: file.filename, content_type: file.mime_type)
end
ProcessedEvent.create!(event_id: event_id)
end
end
MC.messages.get fetches the sealed message from GET https://api.mailcycle.email/messages/:id and opens it with the address’s key inside the job. safe_html has remote images, stylesheets and embeds removed, so it is the field to render in your own UI, and html keeps the original.
Attachments through Active Storage
To keep files in your own S3, Azure or Google Cloud Storage bucket, point Active Storage’s service at it, and every attach above writes there. Until then, each file stays at its address for the address’s retention, and MC.messages.attachment returns it as bytes, already opened, whenever a job or a retry asks.
Backfills with messages.list
Messages stay listable for that retention whether or not a webhook fired. MC.messages.list(address_id) returns the newest first with a next_cursor, so a nightly reconciliation job can walk every project’s address and import anything the webhook path missed.
CloudMailin JSON Normalized fields and their Mailcycle names
| CloudMailin field | Mailcycle (Ruby gem) |
|---|---|
envelope.to |
the event’s inboxId, the id of the address that received it |
headers.from |
from_address and from_name |
headers.to |
to |
headers.subject |
subject |
headers.reply_to |
reply_to, which falls back to the sender when none was set |
headers.message_id |
message_id, for threading a reply |
plain |
text |
html |
html, plus safe_html for display |
attachments[].file_name |
filename |
attachments[].content_type |
mime_type |
attachments[].size |
size |
attachments[].content_id |
content_id |
attachments[].content or url |
MC.messages.attachment(message, file.index) |
Your receiver’s status code on Mailcycle
On Mailcycle, mail is accepted and stored at its address on arrival, so the status your controller returns is about the webhook delivery alone. A delivery that gets no 2xx within 10 seconds is tried again after 1 minute, 5 minutes, 30 minutes, 2 hours, 6 hours, 12 hours and 12 hours, eight attempts across about a day and a half. Each delivery sits in the log for 30 days with its attempt count and last response code.
A deploy that broke the controller is fixed with a replay. Every redelivery keeps its original event id, so the ProcessedEvent check in the job skips anything already imported:
# lib/tasks/mailcycle.rake
task replay_failed: :environment do
hook = ENV.fetch("MAILCYCLE_WEBHOOK_ID")
cursor = nil
loop do
page = MC.webhooks.deliveries(hook, cursor: cursor, limit: 200)
page.deliveries.select { |d| d.status == "failed" }.each { |d| MC.webhooks.redeliver(hook, d.id) }
break unless (cursor = page.next_cursor)
end
end
An API key can read the delivery log and redeliver, so this task runs with the same MC client as the job.
Mail encrypted on arrival
Mail is encrypted the moment it arrives, with keys from your account’s 12-word recovery phrase, and each address has its own key pair. Your Rails app holds the phrase with its other secrets, and with_api_key derives the keys when the process boots. The webhook body holds two ids, so your logs, your error tracker and any proxy in front of the controller only ever see ids. Trackers are stripped in safe_html, so a project’s inbound mail renders in your app without tracking pixels.
When the step after the webhook is a no-code tool rather than Rails, the decrypt Worker runs in your own Cloudflare account, opens one address’s mail and passes the parsed message to n8n, Make, Zapier or Pipedream. The encryption page explains how the phrase becomes each address’s keys.
SDKs in nine languages
The Ruby gem is one of nine SDKs, alongside TypeScript, Python, Go, Rust, Java, .NET, PHP and Swift, all under Apache-2.0. Each has address creation, a signature helper and a message read, so a Laravel service or a Go worker on the same account handles its share of inbound mail in its own language. Install lines are on the SDK pages, and Receive email in Ruby covers the rest of the gem: waiting for mail, folders, an RSpec helper and Sinatra.
Tutorials for the read side exist in every other language too: Node.js, Python, Go, PHP, C#, Java, Rust and Swift.
The MCP server for agents
Teams that pipe email into an app are often adding an agent beside it: one that triages a support queue, reads a confirmation code or drafts a reply. On Scale, mailcycle-mcp runs on the agent’s own machine and gives it tools to list its addresses, read messages, wait for new mail and read attachments. Claude Code, Claude Desktop, Cursor, Codex, VS Code or any other MCP client can use it, and every agent begins in reply-only mode.
Pairing is npx -y mailcycle-mcp pair. See the email MCP server guide for the steps, and AI agent email inbox for an agent working on the same account as your Rails job.
What a month costs: CloudMailin plans and Operator
Figures from CloudMailin’s plans page and from Mailcycle pricing, per month:
| Plan | Price a month | Messages a month |
|---|---|---|
| CloudMailin Starter | $25 | 10,000 emails |
| CloudMailin Professional | $45 | 20,000 emails |
| CloudMailin Premium | $85 | 40,000 emails |
| Mailcycle Operator | $15 | 250,000 received messages |
Operator also includes 250 addresses, API keys and 10 webhooks. Scale, at $19 a month, adds 1,000 addresses, 750,000 received messages, 10 of your own domains, addresses you name yourself, sending from the API and AI agent inboxes. Limits per plan are on plans and limits.
Own domains and replies on Scale
When customers should write to support@example.com or intake@yourcompany.com, Scale adds up to 10 of your own domains and lets you choose the whole local part. Add the domain in the app, prove it with one TXT record and point its nameservers at Mailcycle, which then sets up receiving for you. Scale also sends from the API, so the job can answer from the address that received the mail:
MC.messages.send(
from: project.inbound_email,
to: message.reply_to,
subject: "Re: #{message.subject}",
text: "Thanks, this is now ticket ##{item.id}.",
reply_to: message
)
Passing the original message as reply_to fills in the threading headers. The own domains guide has the domain steps, and Role addresses on your own domain sets up support@ and billing@ this way.
Moving a CloudMailin target, step by step
- List each CloudMailin address and its target URL, and the record in your app that each one feeds.
- Add
mailcycle_address_idandinbound_emailcolumns to those records and create one Mailcycle address per record. - Run the
create_webhooktask in each environment and store the secret and id. - Mount the controller on a new route next to the CloudMailin one, so both run during the switch.
- Port the field reads in your existing handler with the table above, moving the work into the job.
- Hand out the new addresses in your settings screens, forwarding instructions and docs.
- Compare a few days of imports from both paths, then remove the old target. Move a custom domain to Scale last.
Add inbound email to your SaaS builds a whole feature on this pattern, with tickets, threading and reply by email.
Testing the receiver with RSpec
The gem can build the header Mailcycle would send, so a request spec exercises the real check without a live webhook:
RSpec.describe "Inbound mail", type: :request do
it "queues a job for a signed message.received" do
secret = Rails.application.credentials.mailcycle_webhook_secret
body = { id: "evt_1", type: "message.received", createdAt: Time.now.utc.iso8601,
payload: { messageId: "msg_1", inboxId: "inb_1" } }.to_json
header = Mailcycle::WebhookSignature.header(secret, body, Time.now.to_i)
expect {
post "/inbound/mailcycle", params: body,
headers: { "Content-Type" => "application/json", "Mailcycle-Signature" => header, "Mailcycle-Event-Id" => "evt_1" }
}.to have_enqueued_job(InboundMailJob)
end
end
For an end-to-end check on staging, mc.webhooks.test(webhook_id) sends a webhook.test event through the deployed controller, and Send test on the API screen of the app does the same. During development, a Cloudflare Tunnel or ngrok URL in front of rails server works as the webhook URL.
Troubleshooting the move
Every delivery returns 401
A middleware read and rewrote the body before the controller, or the secret in credentials belongs to another environment’s webhook. Verify request.raw_post before any parsing, and rerun the task if the secret was lost.
messages.get returns opened false
The client was built without the phrase, or with another account’s phrase. Pass the phrase the addresses were created under to with_api_key.
Mail lands in the unrouted project
The address was created but its id was never saved, often because provisioning ran in a callback that failed after the API call. Keep update_columns in the same callback, and check the unrouted project after each deploy.
Related reading
- Receive email with a webhook, the production receiver every move shares
- SendGrid Inbound Parse alternative, Mailgun inbound Routes alternative, Postmark inbound alternative and Resend inbound alternative, for other inbound providers
- Receive email in Ruby, the full gem tour
- Run an n8n workflow on every new email
- Webhooks guide, reading mail and the developer overview
Sources and dates
Each CloudMailin statement above was read on 28 November 2026 on these pages:
| What | Page |
|---|---|
| An address generated on sign-up, target URL | https://docs.cloudmailin.com/getting_started/ |
| Custom domains by MX record, paid plan | https://docs.cloudmailin.com/receiving_email/using-your-own-domain/ |
| The three current POST formats and the recommendation | https://docs.cloudmailin.com/http_post_formats/ |
| JSON Normalized fields | https://docs.cloudmailin.com/http_post_formats/json_normalized/ |
| Multipart Normalized fields | https://docs.cloudmailin.com/http_post_formats/multipart_normalized/ |
| Status codes, SMTP outcome, no HTTP retry | https://docs.cloudmailin.com/receiving_email/http_status_codes/ |
| Authorization header per address | https://docs.cloudmailin.com/receiving_email/securing_your_email_url_target/ |
| Plans, prices and monthly emails | https://www.cloudmailin.com/plans |
Mailcycle figures come from https://mailcycle.email/pricing and https://docs.mailcycle.email/concepts/plans-and-limits/. CloudMailin is a trademark of its owner. We are not affiliated with CloudMailin.
FAQ
What is a good CloudMailin alternative for developers?
Mailcycle suits developers who want an inbound address per user, project or customer, created with one API call. Each message.received webhook is signed with HMAC-SHA256 and names the receiving address, and your code reads the full message over REST with an SDK in TypeScript, Python, Go, Rust, Java, .NET, PHP, Ruby or Swift. Mail is encrypted the moment it arrives.
Which CloudMailin POST format matches Mailcycle?
None needs choosing. Every Mailcycle webhook has the same small JSON body with a message id and an address id, and the SDK returns the message as one object with from, to, subject, text, html, the Message-ID and the attachment list. Code written for JSON Normalized or Multipart Normalized maps onto it field by field.
How do I map CloudMailin JSON Normalized fields to Mailcycle?
envelope.to becomes the address id the event carries. headers.from becomes from_address and from_name, headers.subject becomes subject, headers.message_id becomes message_id, plain becomes text and html stays html. Each attachment's file_name, content_type, size and content_id become filename, mime_type, size and content_id, and the bytes come from mc.messages.attachment.
How are Mailcycle webhooks authenticated?
Every delivery carries a Mailcycle-Signature header, an HMAC-SHA256 of a timestamp and the raw body keyed with that webhook's secret, which Mailcycle.verify_webhook_signature checks in Ruby. A webhook can also send an Authorization header of your own on every delivery, set with Add a header in the app.
What happens if my receiver is down when mail arrives?
The mail is already stored at its address, encrypted, for that address's retention. Mailcycle retries the webhook after 1 minute, 5 minutes, 30 minutes, 2 hours, 6 hours, 12 hours and 12 hours, and your code can list the address's messages over REST at any point to catch up.
Which Mailcycle plan fits a CloudMailin workload?
Operator, at $15 a month, includes API keys, 10 webhooks, 250 addresses and 250,000 received messages a month. Scale, at $19 a month, adds 1,000 addresses, 750,000 received messages, 10 of your own domains, addresses you name yourself, sending from the API and AI agent inboxes. Plans are on https://mailcycle.email/pricing.
Do I need MX records to receive email with Mailcycle?
Not on Operator. Addresses are created on shared Mailcycle domains that already receive mail, so a new address takes mail as soon as the API call returns. On Scale, your own domain is proved with one TXT record, and receiving is set up for you once its nameservers point at Mailcycle.
How is inbound mail protected in Mailcycle?
Mail is encrypted the moment it arrives, with keys from your account's 12-word recovery phrase, and each address has its own key pair. Webhook bodies carry ids and no content, and the Ruby gem opens each message inside your own process.
Can an AI agent read the same inbound mail?
Yes. On Scale, mailcycle-mcp runs on the agent's own machine and gives Claude Code, Claude Desktop, Cursor, Codex or any other MCP client tools to list its addresses, read messages, wait for new mail and read attachments.
Receive email in code
- AgentMail Alternative for AI Agent Inboxes (AgentMail alternative)
- Mailgun Inbound Routes Alternative: Route Mail by Address, Not Regex (Mailgun Routes alternative)
- Mailosaur Alternative for Email Testing and Test Inboxes (Mailosaur alternative)
- Mailparser and Parseur Alternative: Incoming Email as JSON on a Webhook (Mailparser and Parseur alternative)
- MailSlurp Alternative for Email Testing and Test Inboxes (MailSlurp alternative)
- Mailtrap Alternative for Email Testing and Test Inboxes (Mailtrap alternative)
- Postmark Inbound Alternative: Addresses by API, Signed Webhooks (Postmark inbound alternative)
- Resend Inbound Alternative: An Address per API Call, Signed Events (Resend inbound alternative)
- SendGrid Inbound Parse Alternative: Inbound Email by API Call (SendGrid Inbound Parse alternative)
- Testmail.app Alternative for Email Testing and Test Inboxes (Testmail.app alternative)
- Test Email Flows on Real Devices with Appium: Read Sign-Up Codes in Python (Appium)
- How to Give a Browser Use Agent an Email Address and Let It Read Its Own Verification Code (Browser Use sign-ups)
- How to Receive Email in C#: Read the Inbox, Save Attachments and Get New Mail Pushed (C# / .NET)
- How to Test Email Verification in Cypress: Receive Sign-Up Codes with cy.task (Cypress)
- Ethereal Email Alternative: Test Nodemailer Emails with an Address per Test (Ethereal Email alternative)
- Golang Receive Email: How to Receive and Read Email in Go (Go)
- How to Read Email in Java: Read the Inbox, Save Attachments and Receive Mail in Spring Boot (Java)
- How to Receive Email in PHP with an Email API: Read the Inbox, Save Attachments and Handle Webhooks (PHP / Laravel)
- How to Receive Email in Python: Read the Inbox, Save Attachments and Get New Mail Pushed (Python)
- Receive Email in Ruby and Rails: Read the Inbox, Save Attachments and Handle Webhooks (Ruby)
- How to Receive Email in Rust: Read the Inbox, Save Attachments and Handle Webhooks in Axum (Rust)
- Add Inbound Email to Your SaaS: Support Intake and Reply-by-Email (SaaS support)
- How to Verify Email in Selenium Tests: Read Sign-Up Codes with Python and pytest (Selenium)
- How to Handle Email Verification in a Stagehand Browser Agent: Create an Address, Wait for the Code, Delete It (Stagehand sign-ups)
- How to Receive Email in Swift: Read the Inbox, Save Attachments and Handle Vapor Webhooks (Swift)
- Test Accounts for Security Testing: a Separate Email Address per Program (Test accounts for security testing)
- How to Automate Email Verification in Tests with Playwright: OTP Codes, Magic Links and Password Resets (Testing email verification)
- How to Receive Email in Node.js: Read the Inbox, Save Attachments and Handle Webhooks (TypeScript / Node.js)
- How to Receive Email with a Webhook: Inbound Email to Your HTTP Endpoint (Webhooks)