Skip to content
ParsedMail

Ruby email parser gems vs a JSON parsing API for Rails apps

ParsedMail is an email parser with a REST API and signed webhooks that returns typed JSON, and this page shows where it fits next to the Ruby email parser gems a Rails app already has. The short answer: the mail gem and Action Mailbox read the message (headers, body, attachments) very well, but none of them pulls business fields such as an order number, a total or a phone number out of free text. That last step is what you either write and maintain yourself or buy.

Try it on a real email, no account needed

Try a sample

No account or card. Demo emails are deleted after 24 hours.

Ruby developer wiring a parsed email webhook into a Rails app

What each Ruby option actually parses

"Ruby email parser" covers three different jobs. Reading the MIME structure of a message. Cutting the quoted reply out of a thread. Turning the text into fields your models can store. The common tools split along those lines.

OptionWhat it gives youWhat it does not do
mail gemA parsed message object: subject, from, to, date, Message-ID, text and HTML parts, decoded attachmentsFind an invoice number or a delivery date inside the body
email_reply_parserThe new text of a reply, without the quoted history and signatureAnything beyond plain text reply cleanup
Action Mailbox (Rails)Inbound routing to mailbox classes, raw email stored with Active Storage, processed emails incinerated after 30 daysField extraction. Inside process you still have a mail object and a body string
Regex or a parser per senderExact fields from senders whose layout never changesSurvive a template change, a forwarded copy or a new supplier
A parsing API such as ParsedMailTyped fields with a confidence score each, as JSON by webhook or API responseRun inside your process. It is an external service with a monthly plan

The first three are free and you should use them. The cost question only starts at the fourth row, when someone has to write and keep the extraction rules.

Where the mail gem stops

The mail gem is the base most Ruby code builds on, and Action Mailbox hands you one of its objects. Reading a message takes a few lines:

require "mail"

mail = Mail.new(File.read("order.eml"))
mail.subject                 # "Order #10482 confirmed"
mail.from                    # ["[email protected]"]
body = mail.multipart? ? mail.text_part&.decoded : mail.body.decoded
mail.attachments.map(&:filename)  # ["invoice-10482.pdf"]

Everything after this line is your code. The order number is somewhere in body, possibly only in the HTML part, possibly in a PDF. The total might read "$1,284.50", "USD 1284.50" or "Total due 1.284,50". A forwarded copy adds a "Begin forwarded message" block and a second sender.

Teams typically start with a regex per sender. That works for the first two or three. Each new supplier, CRM form or marketplace adds a branch, and each template change at the sender breaks one silently. The failure mode matters: a regex that stops matching returns nil, and a regex that matches the wrong number returns a confident wrong value.

Action Mailbox plus a parsing API

If your app already receives mail through Action Mailbox, you do not have to change that. Keep the routing, and send the raw message to the synchronous parse endpoint from the mailbox. The API accepts the raw MIME in raw and a plain English field list in description, and reads PDF attachments from the same message.

class OrdersMailbox < ApplicationMailbox
  def process
    uri = URI("https://parsedmail.com/api/v1/parse")
    req = Net::HTTP::Post.new(uri, "Content-Type" => "application/json",
      "Authorization" => "Bearer #{ENV.fetch("PARSEDMAIL_KEY")}")
    req.body = { raw: mail.to_s,
      description: "order number, customer email, total, delivery date" }.to_json
    res = Net::HTTP.start(uri.host, uri.port, use_ssl: true) { |h| h.request(req) }
    result = JSON.parse(res.body)

    Order.create!(number: result.dig("data", "order_number"),
                  total: result.dig("data", "total", "amount"),
                  confidence: result["confidence_avg"])
  end
end

Each call counts one email plus the attachment pages it reads, and nothing is stored on the ParsedMail side. The rate limit is 120 requests per minute per workspace, so a mailbox processing a burst should run in a background job and respect the Retry-After header on a 429. The full parameter list is in the API reference.

Receiving parsed emails by webhook in Rails

The other route skips Action Mailbox. Senders or a mailbox rule forward to a ParsedMail inbox address, and each parsed email arrives at your Rails app as a signed POST. The signature header is ParsedMail-Signature: t=<unix seconds>,v1=<hex>, an HMAC-SHA256 of <t>.<raw body> with the endpoint secret.

class ParsedmailWebhooksController < ActionController::API
  def create
    raw   = request.raw_post
    parts = request.headers["ParsedMail-Signature"].to_s.split(",").to_h { _1.split("=", 2) }
    t     = parts["t"].to_i
    expected = OpenSSL::HMAC.hexdigest("SHA256", ENV.fetch("PARSEDMAIL_SECRET"), "#{t}.#{raw}")

    return head(:bad_request) unless ActiveSupport::SecurityUtils.secure_compare(expected, parts["v1"].to_s)
    return head(:bad_request) if (Time.now.to_i - t).abs > 300

    email = JSON.parse(raw)["data"]
    ParsedEmailJob.perform_later(email) unless email["needs_review"]
    head :ok
  end
end

Compute the HMAC over raw_post, before any JSON parsing, or the bytes will not match. Answer with a 2xx quickly and do the work in a job; anything else is retried five times over about 14 hours. Every attempt carries the same Idempotency-Key, so store it and skip repeats. The webhooks documentation has the payload and the retry schedule.

A worked order email, regex vs typed JSON

Take one order confirmation forwarded by a sales rep. The body says "Thanks, we have your PO 7731-B. Order #10482 ships Tuesday, December 1. Total due USD 1,284.50." A regex written for the original sender expects "Order number: 10482" and "Total: $1,284.50". It matches neither line, so the job either fails or saves nil.

The same email sent to the parse endpoint with "order number, purchase order, total, ship date" returns:

{
  "data": {
    "order_number": "10482",
    "purchase_order": "7731-B",
    "total": {"amount": 1284.5, "currency": "USD"},
    "ship_date": "2026-12-01"
  },
  "confidence": {"order_number": 0.97, "purchase_order": 0.95, "total": 0.98, "ship_date": 0.91},
  "confidence_avg": 0.95
}

The money comes back as an amount and a currency, the date as ISO 8601, and a value the email does not state comes back as null rather than a guess. The confidence scores give your code a rule to follow: save above your threshold, route the rest to a person. On Growth that person works in a review queue instead of your admin panel.

What it costs at 1,000 emails a month

The gems are free. The cost of the do it yourself route is developer time for each sender and each breakage, which only you can estimate. The plan side is fixed, from the pricing page:

Emails a monthPlanMonthly billingBilled yearly, per monthIncluded
Up to 1,000Starter$49$241,000 emails, 300 attachment pages, 5 inboxes
Up to 5,000Growth$149$745,000 emails, 2,000 pages, 25 inboxes, review queue
Up to 25,000Scale$499$24925,000 emails, 10,000 pages, unlimited inboxes

A simple test: if your team would spend more than one or two developer hours a month writing and fixing sender rules, Starter at $24 a month billed yearly is the cheaper line. If you have one sender whose template has not changed in years, keep the regex.

Who this is for and who it is not for

It is for Rails teams that receive order, lead, invoice or booking emails from many senders and want typed records in their database without a growing file of regexes. It also suits a team that already runs Action Mailbox and wants to add extraction without moving its inbound setup. The email parsing API page shows the same approach for any language.

It is not for an app that only needs headers, reply text or attachments, which the mail gem and email_reply_parser already give you for free. It is also not the right call when policy forbids sending email content to any outside service.

Frequently asked questions

What is the best Ruby email parser?

For reading the message itself, the mail gem is the standard, and Action Mailbox uses it. For extracting business fields such as order numbers or totals from many senders, a parsing API that returns typed JSON saves the regex work. ParsedMail starts at $24 a month billed yearly.

Can Action Mailbox extract fields from an email?

No. Action Mailbox routes inbound email to mailbox classes and stores the raw message with Active Storage. Inside the process method you get a mail object and its body, and the extraction of fields such as an invoice number is still your code or an API call.

Is there a Ruby gem for the ParsedMail API?

There is no official gem. The API is plain JSON over HTTPS with a Bearer key, so Net::HTTP or any HTTP client works, as in the examples on this page. Webhook signatures are verified with OpenSSL::HMAC from the standard library.

How do I parse PDF attachments in Ruby emails?

The mail gem gives you each attachment as decoded bytes, but reading the PDF text and its fields is a separate job. Sending the raw message to the parse endpoint reads the attachments with the email and counts their pages against your plan.

More from the blog

See your own email as JSON

Paste one into the demo, describe the fields and look at the result. No account needed.