a9script

Docs / Files, mail, documents

a9script authoring pack — email functions

The email functions, with their arguments and a line of real script each. Called by bare name; nothing is imported. A call marked pauses does real work outside the script: the run is saved, and continues on the next line with the result.

This is one part of the authoring pack — how a script is executed at all is the model part, and the other groups of functions are parts of their own. All of them are named at the end.

Generated — do not edit. Every block of script below is executed by the platform’s own test suite, and every error message is the one the platform produces today, so none of this can be what was true when someone last wrote it down.

sendMail(message) — pauses

Sends an email through one of the environment’s mail accounts. The message says what to send; which server and which credentials is the account’s configuration, so a script never holds a password. When the environment has exactly one account it is used by default — name one in account when there are several.

  • message (object){ to, subject, text?, html?, cc?, bcc?, from?, replyTo?, account?, attachments? }. Recipients (to, cc, bcc) are addresses as text — comma-separated — or a list of them. text and html are the two ways to say the body; give both and the reader’s mail client picks. from replaces the account’s own address as the visible sender (“Alerts alerts@acme.example”). attachments is a list of { filename, contentBase64, contentType?, cid? } — contents as base64 text, the same shape createPdf answers; give an attachment a cid and the html body can show it inline as <img src="cid:...">. Any other field is refused by name.

Answers: { ok: true, mode, messageId? } — the send succeeded. mode is what the account did with it: deliver sent it as written, redirect sent it to the addresses configured on the account instead of the recipients you named, and record sent nothing and wrote the message into this run’s log. messageId is the identifier the mail server will show the message under, when there was a send and it stated one. Under record the answer also carries recorded{ to, cc, bcc, subject, body }, the message that was not sent. A send that cannot happen — no account, an unknown account name, several accounts and none named, contents that are not base64, a server that refuses — raises a catchable error saying which, naming the account.

const report = createPdf({
  title: "Weekly report",
  blocks: [{ kind: "heading", level: 1, text: "Weekly report" }]
});
const receipt = sendMail({
  to: "ops@acme.example",
  subject: "Weekly report",
  text: "The report is attached.",
  attachments: [{ filename: "report.pdf", contentBase64: report, contentType: "application/pdf" }]
});
log("sent as " + receipt.messageId);

The rest of this pack

The page above is everything that is true only HERE. Ask for these parts by name for the rest:

  • model — how a script is executed, the shape of its input, the rules enforced while it runs, and the mistakes that do not work here.
  • functions-core — the core functions — what each one does, its arguments, whether it pauses the run, and a line of real script.
  • functions-encoding — the encoding functions — what each one does, its arguments, whether it pauses the run, and a line of real script.
  • functions-crypto — the crypto functions — what each one does, its arguments, whether it pauses the run, and a line of real script.
  • functions-text — the text functions — what each one does, its arguments, whether it pauses the run, and a line of real script.
  • functions-number — the numbers functions — what each one does, its arguments, whether it pauses the run, and a line of real script.
  • functions-structured — the structured data functions — what each one does, its arguments, whether it pauses the run, and a line of real script.
  • functions-document — the documents functions — what each one does, its arguments, whether it pauses the run, and a line of real script.
  • functions-markdown — the markdown functions — what each one does, its arguments, whether it pauses the run, and a line of real script.
  • functions-datetime — the date & time functions — what each one does, its arguments, whether it pauses the run, and a line of real script.
  • functions-blob — the files functions — what each one does, its arguments, whether it pauses the run, and a line of real script.
  • functions-mapping — the mapping functions — what each one does, its arguments, whether it pauses the run, and a line of real script.
  • functions-dataset — the datasets functions — what each one does, its arguments, whether it pauses the run, and a line of real script.
  • functions-state — the state functions — what each one does, its arguments, whether it pauses the run, and a line of real script.
  • functions-pagination — the pagination functions — what each one does, its arguments, whether it pauses the run, and a line of real script.
  • functions-control — the run control functions — what each one does, its arguments, whether it pauses the run, and a line of real script.
  • functions-functions — the config functions — what each one does, its arguments, whether it pauses the run, and a line of real script.
  • mistakes — the habits from general JS that do not work here — each with the exact error it produces and the shape to write instead.
  • standard-library — every built-in the language itself provides — JSON, Math, Object, String, Array, Number, Map, Set, Date, RegExp and the bare globals — one line each, with an example and its answer.
Rendered from docs/guide/authoring-pack-functions-email.md in the product's own repository, at build time. Found a problem on this page? Write to the address in the footer.