Skip to the documentation
Ruby

Send an email

`emails.send`: one message, now or later.

emails.send

send_email.rb
email = client.emails.send(  from: {email: "[email protected]", name: "Acme Billing"},  to: ["[email protected]", "Grace <[email protected]>"],  cc: "[email protected]",  bcc: [{email: "[email protected]"}],  replyTo: "[email protected]",  subject: "Your September invoice",  html: "<p>Invoice attached.</p>",  text: "Invoice attached.",  headers: {"X-Campaign" => "invoices"},  attachments: [{filename: "invoice.pdf", content: Pathname("invoice.pdf")}],  threadId: "CAHk7pQ2x9LmZ4-mail.example.com",  scheduledAt: "PT1H",  tags: {order: "4021"},  tracking: {opens: true, clicks: true}) puts email[:id], email[:status]

to, cc and bcc take one recipient or an Array of them, and a lone one is wrapped for you. Each may be a bare address, Name <addr@host>, or a Hash with email and name.

The message goes in as keyword arguments, or as one Hash. Keyword arguments beside a Hash are merged into it and win where both name a field, so client.emails.send(message, subject: "Re: your invoice") changes one field of a message you built earlier. The keys keep the API’s names, which is why replyTo and scheduledAt stay camelCase, while idempotency_key: and api_key: are options of the call and never part of the message.

Parameters

fromString or Hashrequired
The sender. A bare address, `Name <addr@host>`, or a Hash with `email` and `name`. Must be one this key may send as, or the call raises a 403 `from_address_forbidden`. There is no fallback sender, so a send always names the address it goes out as.
toString, Hash or Arrayrequired
One recipient or an Array of them, and a lone one is wrapped for you. At most 50 across `to`, `cc` and `bcc` combined, and more is a 422 `too_many_recipients`.
ccString, Hash or Array
Counts toward the 50-recipient limit.
bccString, Hash or Array
Never named in the bytes anyone else receives, because one envelope is transmitted per recipient. Counts toward the 50 as well.
replyToString or Hash
A single address, sent as the Reply-To header.
subjectString
At most 998 characters, the RFC 5322 line limit. Defaults to empty, and an empty subject falls back to the template’s or the draft’s.
htmlString
One of `html`, `text`, `draftId` or `template` is required. HTML is what recipients see when both `html` and `text` are given. At most 1,000,000 characters.
textString
The plain-text part, at most 1,000,000 characters.
templateHash
Render a stored template server-side: a Hash with `id`, which takes an id or a slug, and optional `version` (an Integer), `props` and `slots`. `version` pins a revision. Leave it out to use whatever is published when the request is accepted. An unknown or missing prop is a 422 rather than a blank in the message.
draftIdString
Send a saved draft under this envelope, as it was written. Cannot be combined with `template` or `translate`.
headersHash
Header name to String value, limited to `X-*`, `List-*`, Reply-To, Precedence, Auto-Submitted, Importance, Priority and Feedback-ID. Anything the transport sets itself is refused with a 422 `reserved_header` rather than quietly dropped.
attachmentsArray<Hash>
Each a Hash with `filename`, `content` and an optional `contentType`, or a Hash with only `fileId`, naming a file already in the workspace, such as one from `files.upload`. Pass bytes for `content` and they are base64-encoded for you. 20 files, with inline files capped at 5 MB in total once decoded. A stored file can be larger and travels as a download link.
attachmentDeliveryString
`mime`, `link` or `auto`. `auto` carries files as download links once they pass 2 MB on a domain with an active files domain, and inside the message otherwise. Left out, the mailbox setting applies, and that defaults to `auto`.
threadIdString
Reply into an existing thread. The transport writes In-Reply-To and References.
scheduledAtTime, DateTime or String
A Time or a DateTime, sent as a UTC ISO 8601 instant, an ISO 8601 instant as a String, or a duration like `PT1H`. Up to a year out, never in the past. Cannot be combined with `cancellableForSeconds`. A Ruby Date is sent as a bare date, which the API reads as midnight UTC on that day, so pass a Time when the hour matters.
cancellableForSecondsInteger
0 to 900. An undo window on an immediate send: the composer’s undo mechanism, exposed rather than hardcoded.
tagsHash
Up to 10 labels, with keys of 1 to 64 letters, digits, `_` or `-` and String values up to 256 characters. Echoed back on every read and never interpreted.
signatureBoolean
Whether this message carries the signature of the address it is sent from: that address’s own, else the catch-all’s for an address a catch-all caught, else the OpenEmail footer unless that address turned it off. Left out, an `html` body goes out exactly as written without one and a `text`-only body carries it. Set `false` for the mail a program sends on somebody’s behalf, such as a receipt, a password reset or a digest, none of which want a person’s sign-off under them. Template sends and encrypted sends never carry one.
trackingHash
A Hash with optional Boolean `opens` and `clicks`: whether to add an open pixel and rewrite links for this message. Off unless tracking was turned on for the address it is sent from (or the catch-all that caught it), and either key stated here settles that one message whichever way the address is set.
translateHash
Send it in the recipient’s language: a Hash with `to` and optional `from`, `subject` and `includeOriginal`. `to` takes a code, an English name or the language’s own name, and `subject` and `includeOriginal` both default to true. Settled when the request is accepted, so a scheduled message carries the words that were approved. Refused alongside `draftId`.
idempotency_keyString
Your own key for this send, 1 to 255 characters of letters, digits, `_`, `.`, `:` or `-`. Without one the client generates a key for each call, so its own retries never send twice, and with one a send that runs again in another process replays instead of repeating.
api_keyString
Sends with this key instead of the client’s, for a process sending on behalf of several workspaces.

Response

A Hash with Symbol keys, so email[:status] reads the status.

idString
The send id, `msg_` followed by 24 hex characters. Use it for `get`, `cancel`, `reschedule` and `get_tracking`.
statusString
queued, scheduled, sending, sent, partial, bounced, cancelled or failed. Read this rather than the fact that the call returned: an immediate send is dispatched inside the request and usually comes back `sent`, `partial` or `failed`, and a held one comes back `queued` or `scheduled`. `partial` is its own state: some recipients have it and cannot be un-sent, so retrying is wrong and reporting failure is a lie.
modeString
`live` or `test`: which kind of key sent it. A test send is recorded and never transmitted. It reads `sent`, with `transport` set to `test`, so assert on the response and not on an inbox.
fromString
The address actually authorised and put on the wire, which is not always the one asked for.
subjectString or nil
As sent.
messageIdString or nil
The RFC 5322 Message-ID. nil until the MIME exists. The sending service rewrites the header on the way out, so no bounce or delivery report carries this value. `id` is what an event comes back on.
threadIdString or nil
The thread it landed in.
transportString or nil
How the message left. nil until dispatch.
attemptsInteger
How many times dispatch has been tried.
lastErrorString or nil
Why the last attempt failed, verbatim.
scheduledAtString or nil
The ISO 8601 instant it is due to go.
cancellableUntilString or nil
While now is before this, `cancel` still works.
sentAtString or nil
The ISO 8601 instant it left.
tagsHash
What you sent, echoed back.
sourceString
composer, api, mcp, ai or queue: which surface asked. `api` is this client.
createdAtString
The ISO 8601 instant the record was written.
replayedBoolean
True when an Idempotency-Key matched a send that already existed. Nothing new was sent, and this is the original message as it is now.
translationHash
Present only on a message that was translated, and only where the whole stored request is carried: this response and `get`. It holds `language`, `languageName`, `detectedSourceLanguage`, `subject` and `includeOriginal`, with codes rather than whole language rows. A list row never has it, so its absence there says nothing either way.

In the recipient’s language

translate writes the message in somebody else’s language before it goes. The body, and the subject unless you turn that off, is translated when the API accepts the request, and what came out is what goes out: a translation that could not be produced refuses the send rather than posting it in the language you wrote it in.

translate.rb
email = client.emails.send(  from: "[email protected]",  to: "[email protected]",  subject: "Your September invoice",  html: "<p>Invoice attached. Payment is due on the 14th.</p>",  translate: {to: "de"}) p email[:translation]

email[:translation] then reads {language: "de", languageName: "German", detectedSourceLanguage: "en", subject: true, includeOriginal: true}.

Nobody read that before it went. emails.translate is the same round trip stopped one step early. Show it to a person, let them change it, then send what they approved with no translate on the call at all. Passing it again would translate a second time and discard their edits.

preview_translation.rb
preview = client.emails.translate(  subject: "Your September invoice",  html: "<p>Invoice attached. Payment is due on the 14th.</p>",  to: "de") puts preview.dig(:language, :native), preview[:subject], preview[:html]print "Send it as it is? [y/N] " if $stdin.gets.to_s.strip.casecmp?("y")  client.emails.send(    from: "[email protected]",    to: "[email protected]",    subject: preview[:subject],    html: preview[:html]  )end
languages.rb
p OpenEmail::LANGUAGES.size current = client.languages.listp current.size p OpenEmail.resolve_language("Deutsch")&.fetch(:code)p OpenEmail.resolve_language("zh-TW")&.fetch(:code)p OpenEmail.language_by_code("DE")&.fetch(:native)p OpenEmail.rtl_language?("ar")

Those lines print 200, the rows this version ships with, then how many the API holds now, then "de", "zh-Hant", "Deutsch" and true. The table is bundled, in picker order, as OpenEmail::LANGUAGES, a frozen Array of Hashes with code, label, native, flag and rtl, so a picker can be filled before the first request. languages.list returns the same rows off the wire as a plain Array, for a caller who would rather have the current ones than the ones this version shipped with. OpenEmail.resolve_language takes a code, an English name, an endonym or an alias (zh-TW is an alias of a code no longer listed) and returns nil when nothing matches, OpenEmail.language_by_code matches an exact code in any case, and sixteen of the rows are right to left. Search native, label and code together, show native first, and store the code.

emails.translate is not retried automatically. It spends model calls and writes nothing, so there is nothing to make idempotent and a retry after an unanswered request would only buy the same answer twice.

  • A language the API cannot match is a validation_error on translate.to, before anything is sent.
  • translation_too_long over 30,000 characters, translation_not_configured when the install has no AI configured, a 429 ai_quota_exceeded when the workspace has used today’s AI actions (it resets at midnight UTC and is not retried), translation_failed when the provider did not answer. None of them sends the message untranslated as a fallback.
  • Works with template: the RENDERED output is what gets translated, so one stored body serves every language your customers read in. A template that renders a whole document keeps its doctype, its <style> blocks and its @font-face rules: only the body goes to the model and the rest is put back around it. Its <title> is left alone, which nothing displays anyway.
  • A retry costs nothing extra. The translation is not part of the idempotency fingerprint (the request is, translate included), so retrying an unanswered send with the same Idempotency-Key replays the message that already exists rather than translating and sending a second one.
  • A translated message that is queued or scheduled keeps its approved wording. emails.reschedule still moves it, while emails.update refuses new wording with a 409 translation_locked, so changing what it says means cancelling and sending again.

Attachments

content is base64 on the wire. Pass the bytes and they are encoded for you: a binary String such as File.binread returns, an IO such as an open File, or a Pathname, which is read for you.

attachments.rb
attachments = [  {filename: "invoice.pdf", content: File.binread("invoice.pdf"), contentType: "application/pdf"},  {filename: "report.pdf", content: Pathname("report.pdf")},  {fileId: "file_6bb640f5b99e47deb758f1f5"}] client.emails.send(  from: "[email protected]",  to: "[email protected]",  subject: "Your documents",  text: "Both are attached.",  attachments:)

A String tagged as text, such as File.read returns, is taken to be base64 already, and one that is not base64 raises ArgumentError before anything is sent. Read files with File.binread, or call .b on bytes that arrived tagged as text.

OpenEmail.to_base64 is there if you need the same encoding elsewhere. It takes a binary String, an IO or a Pathname and returns strict base64, with no line breaks.