Skip to the documentation
Python

Send an email

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

emails.send

send_email.py
from openemail import openemail email = openemail.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': pdf_bytes}],    'threadId': 'thread_…',    'scheduledAt': 'PT1H',    'tags': {'order': '4021'},    'tracking': {'opens': True, 'clicks': True},})

to, cc and bcc take one recipient or many, and a lone one is wrapped for you. Each may be a bare address, Name <addr@host>, or {'email': ..., 'name': ...}.

Parameters

fromRecipientInputrequired
The sender. A bare address, `Name <addr@host>`, or a dict. Must be one this key may send as. There is no fallback sender, so a send always names the address it goes out as.
toRecipientInput | list[RecipientInput]required
One recipient or many; a lone one is wrapped for you. At most 50 across to, cc and bcc combined.
ccRecipientInput | list[RecipientInput]
Counts toward the 50-recipient limit.
bccRecipientInput | list[RecipientInput]
Never named in the bytes anyone else receives, because one envelope is transmitted per recipient.
replyToRecipientInput
A single address, sent as the Reply-To header.
subjectstr
At most 998 characters, the RFC 5322 line limit. Defaults to empty.
htmlstr
One of html, text, draftId or template is required. HTML is what recipients see when both html and text are given.
textstr
The plain-text part.
templateEmailSendTemplate
Render a stored template server-side. `version` pins; omit it 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.
draftIdstr
Send a saved draft under this envelope.
headersdict[str, str]
`X-*`, `List-*`, Reply-To, Precedence, Auto-Submitted, Importance, Priority and Feedback-Id. Anything the transport sets itself is refused rather than quietly dropped.
attachmentslist[AttachmentInput]
`{'filename': ..., 'content': ...}` with an optional `'contentType'`, or `{'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.
attachmentDeliveryAttachmentDeliveryMode
`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`.
threadIdstr
Reply into an existing thread. The transport writes In-Reply-To and References.
scheduledAtdatetime | str
A `datetime`, an ISO-8601 instant, or a duration like `PT1H`. Up to a year out, never in the past. Cannot be combined with cancellableForSeconds.
cancellableForSecondsint
0 to 900. An undo window on an immediate send: the composer’s undo mechanism, exposed rather than hardcoded.
tagsdict[str, str]
Up to 10 labels, echoed back and filterable. Never interpreted.
signaturebool
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.
trackingTrackingRequest
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 field stated here settles that one message whichever way the address is set.
translateSendTranslateOptions
Send it in the recipient’s language. `to` takes a code, an English name or the language’s own name; `subject` and `includeOriginal` both default to true. Resolved when the request is accepted, so a scheduled message carries the words that were approved. Refused alongside `draftId`.

Response

idstr
The send id, `msg_…`. Use it for `get`, `cancel`, `reschedule` and `get_tracking`.
statusEmailStatus
queued, scheduled, sending, sent, partial, bounced, cancelled or failed. Read this rather than the fact the call returned. `partial` is its own state: some recipients have it and cannot be un-sent, so retrying is wrong and reporting failure is a lie.
modeApiKeyMode
Which kind of key sent it. A test send is recorded and never transmitted.
fromstr
The address actually authorised and put on the wire, which is not always the one asked for.
subjectstr | None
As sent.
messageIdstr | None
The RFC 5322 Message-ID. Null 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.
threadIdstr | None
The thread it landed in.
transportEmailTransport | str | None
How the message left. Null until dispatch.
attemptsint
How many times dispatch has been tried.
lastErrorstr | None
Why the last attempt failed, verbatim.
scheduledAtstr | None
ISO instant it is due to go.
cancellableUntilstr | None
While now is before this, cancel still works.
sentAtstr | None
ISO instant it left.
tagsdict[str, str]
What you sent, echoed back.
sourceEmailSource | str
composer, api, mcp, ai, oauth or form: which surface asked. `api` is this client on an API key, and `oauth` is this client on an access token.
createdAtstr
ISO instant the record was written.
replayedbool
True when an Idempotency-Key matched a send that already existed. Nothing new was sent, and this is the original message.
translationNotRequired[EmailTranslationResource]
Present only on a message that was translated, and only where the whole stored request is carried: this response and `get`. A dict of `language`, `languageName`, `detectedSourceLanguage`, `subject` and `includeOriginal`, all codes rather than language rows. A list row never has it, so its absence there says nothing either way. Read it with `email.get('translation')`.

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.py
from openemail import openemail email = openemail.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'},}) print(email.get('translation'))

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 throw their edits away.

preview_translation.py
from openemail import openemail preview = openemail.emails.translate({    'subject': 'Your September invoice',    'html': '<p>Invoice attached. Payment is due on the 14th.</p>',    'to': 'de',}) print(preview['language']['native'], preview['detectedSourceLanguage'])print(preview['html']) approved_subject = input(f"Subject [{preview['subject']}]: ") or preview['subject'] or '' openemail.emails.send({    'from': '[email protected]',    'to': '[email protected]',    'subject': approved_subject,    'html': preview['html'] or '',})
render_picker.py
from openemail import LANGUAGES, is_rtl_language, language_by_code, openemail, resolve_language current = openemail.languages.list() german = resolve_language('Deutsch')traditional = resolve_language('zh-TW')upper = language_by_code('DE') assert len(LANGUAGES) == 200assert german is not None and german['code'] == 'de'assert traditional is not None and traditional['code'] == 'zh-Hant'assert upper is not None and upper['native'] == 'Deutsch'assert is_rtl_language('ar')

The table is bundled, in picker order, so a picker can be filled before the first request. languages.list() returns the same rows off the wire as a plain list, for a caller who would rather have the current ones than the ones this version shipped with. resolve_language takes a code, an English name, an endonym or an alias (zh-TW is an alias of a code no longer listed), language_by_code matches an exact code case-insensitively, 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 that resolves to nothing 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 is frozen against wording changes. emails.reschedule still moves it; changing what it says means cancelling and sending again.

Attachments

content is base64 on the wire. Pass bytes and they are encoded for you.

attachment.py
from pathlib import Path from openemail.types import AttachmentInput attachments: list[AttachmentInput] = [    {        'filename': 'invoice.pdf',        'content': Path('invoice.pdf').read_bytes(),        'contentType': 'application/pdf',    },]

to_base64 is exported if you need it elsewhere. A str in content is sent as it is, so it has to be base64 already.

Reference