mail_send_message
Compose and send a new email from scratch, or save it to Drafts for review by setting draft=true.
Instructions
Compose a new email from scratch and send it, or save it to Drafts with draft=true.
Use when: the owner asks you to write to someone and has agreed the recipients and text. Not for answering a message (use mail_reply_to_message, which keeps the thread), passing one on with its attachments (use mail_forward_message), or sending an existing draft (use mail_send_draft). Parameters:
to, cc and bcc take 'anna@example.org' or 'Anna anna@example.org'; a bare name is refused.
body is plain text; body_html, if given, goes alongside it as multipart/alternative. The owner's signature (EMAIL_SIGNATURE) is appended to both.
Each attachment may be at most MAX_ATTACHMENT_BYTES (default 5 MB).
Omitted cc, bcc, body_html and attachments are simply left out.
draft=true only saves to Drafts: no approval, no recipient checks, nothing leaves. Behavior:
With SEND_REQUIRES_APPROVAL=true (the default) the message is NOT sent: it is queued on the owner's approval page (expires after 24 h by default) or, on a local server, saved to Drafts for the owner to send. With it off, it goes out at once and a copy is saved to Sent.
Recipients are checked first: at most MAX_RECIPIENTS (default 25) across to, cc and bcc, and only SEND_ALLOWLIST addresses if that list is set.
Every call is a new message, so never repeat one to be sure. Returns: {status, recipients, message_id, subject, to, cc}; layout_warnings flags Windows line endings, HTML tags in body, or one long paragraph. status is one of:
sent: saved_to names the Sent folder; refused lists addresses the server rejected.
queued_for_owner_approval: sent=false, outbox_id, approve_at, expires_in_seconds and a notice to tell the owner.
saved_to_drafts_for_owner_approval or draft_saved: folder, but no uid; find it with mail_search_messages(folder='Drafts'). Errors:
an unusable, disallowed or excess recipient, or an oversized attachment.
a full approval queue: do not retry; tell the owner.
an SMTP failure: check Sent before retrying, it may have gone out.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| cc | No | Cc addresses (visible to all recipients). | |
| to | Yes | Addresses: 'anna@example.org' or 'Anna <anna@example.org>'. Only a name? contacts_search_contacts, then mail_find_correspondent. | |
| bcc | No | Bcc addresses (hidden from other recipients). | |
| body | Yes | Plain-text message body. The server appends the owner's signature. | |
| draft | No | true = save to Drafts for the user to review instead of sending. | |
| subject | Yes | Subject line. | |
| body_html | No | Optional HTML version of the body; the plain-text 'body' is always required. | |
| attachments | No | Files to attach (from mail_get_attachment as is; from drive_get_file, name and data_base64 go in filename and content_base64). |