record_email_send()
Send an email logged on a record's thread, exactly like the UI's email-on-record feature: it creates an email_out comment, sets a token Reply-To so replies thread back onto the record, and can attach the record's files. Posted as the System user.
For a plain fire-and-forget email with no record link, use smtp_email_send() instead.
Syntax
record_email_send(connection, spec, table, recordId)
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
connection |
string | yes | Name of the SMTP integration connection to send through. |
spec |
array | yes | The email (see keys below). |
table |
string | yes | Table name or database table id of the record. |
recordId |
int | yes | The record's primary key. |
spec keys: to (string or list — recipient emails or a user field), subject, html (body), from? ("Name <email>"; defaults to the connection's sender identity), attach_field? (a file field id whose files to attach), attach_pattern? (glob like *.pdf, comma-separated allowed).
Returns
true once queued. Throws if the connection, From address, or recipients are missing/invalid.
Example
record_email_send("Main SMTP", [
"to" => $record["email"],
"subject" => "Your invoice " . $record["number"],
"html" => "<p>Hi " . $record["name"] . ", your invoice is attached.</p>",
"attach_field" => "documents",
"attach_pattern" => "*.pdf"
], "invoices", $record["_meta"]["id"]);
Example output
true
Notes
- Replies thread back onto the record as
email_incomments. - Send failures are logged to the run log (status "E") and the comment is marked
dropped— they do not throw. - Pair with pdf_generate() to generate and email a document.
See also: smtp_email_send(), pdf_generate()