Mail & Redirection

OcaltQL sends email with the MAIL verb and performs HTTP redirects with REDIRECT. Both are fire-and-forget operations - they do not return a value and do not use SET. All modifiers are optional and can appear in any order.

MAIL

The MAIL verb sends an email. The body type - TEXT or HTML - is declared before BODY. All string delimiters are interchangeable. All modifiers can appear in any order.

Basic Email

Plain Text Email
MAIL TEXT BODY 'hello world' TO 'email@email.com' SUBJECT 'this is a subject'
HTML Email
MAIL HTML BODY '<h1>Hello</h1><p>World</p>' TO 'email@email.com' SUBJECT 'HTML message'

Recipients

Multiple recipients are comma-separated inside the TO value. CC and BCC follow the same pattern.

Multiple Recipients
MAIL TEXT BODY 'hello' TO 'email@email.com, email@email.co' SUBJECT 'multi recipient'
CC and BCC
MAIL TEXT BODY 'message' TO 'boss@site.com' CC 'team@site.com' SUBJECT 'report'
AFTER MAIL TEXT BODY 'message' TO 'boss@site.com' BCC 'secret@site.com' SUBJECT 'hidden copy'

Headers, Reply-To, and Attachments

Send from one of your own mailboxes
MAIL HTML BODY '<p>Your quote is attached.</p>' HEADER 'From: Sales <sales@yourdomain.com>' TO 'client@site.com' SUBJECT 'Your quote'
Who a message is from. With no From header a message leaves as Ocalt <no-reply@ocalt.com>. HEADER 'From: Name <address>' sends it from that mailbox instead, so the person reading it sees who wrote it and a reply comes back to that mailbox. The address has to be a mailbox on your own account (one you created in Ocalt Email or with EMAIL ACCOUNT ADD). Any other address is refused with You can only send from a mailbox on your own account, and nothing is sent. An HTML message also carries the same words as plain text, which is what mail filters expect of a message written by a person.
Other headers
MAIL TEXT BODY 'hello' HEADER 'X-Campaign: spring' TO 'email@email.com' SUBJECT 'with header'

The headers carried are From (as above), anything starting with X-, In-Reply-To, References, List-Unsubscribe, List-Unsubscribe-Post, List-Id, Auto-Submitted and Precedence. To, Cc, Bcc, Subject and Reply-To are set with their own modifiers and cannot be overwritten from HEADER.

Reply-To
MAIL TEXT BODY 'help needed' TO 'support@site.com' SUBJECT 'support' REPLY TO 'user@site.com'
Attachment
MAIL TEXT BODY 'see attached' TO 'client@site.com' SUBJECT 'invoice' ATTACH '/root/invoice.pdf'
Several attachments
MAIL TEXT BODY 'both attached' TO 'client@site.com' SUBJECT 'invoice and statement' ATTACH '["/root/invoice.pdf", "/root/statement.pdf"]'

ATTACH takes one path, or a JSON list of paths for several files. Every file is read from your namespace, and together they can be up to 25 MB. If one of them does not exist the message is not sent, and the error names the file.

Knowing whether it was sent

MAIL fails when a recipient is not a valid address, an attachment is missing, the From mailbox is not yours, or you are sending too fast. A failure does not stop the script on its own, so catch it wherever the answer matters:

Catch a failed send
MAIL TEXT BODY 'hello' TO 'client@site.com' SUBJECT 'hi' OR CATCH ERROR SET ?why
AFTER IF ?why IS SET
OPEN
  EMIT ?why("message")
  AFTER EXIT
CLOSE
AFTER EMIT "sent"

String Delimiters and Modifier Order

Any of the three string delimiters can be used throughout MAIL; a backtick string keeps its content exactly as written, which suits a body with backslashes in it. All modifiers can appear in any order after the verb.

Mixed Delimiters
MAIL HTML BODY "hello" HEADER 'From: sender@site.com' TO `email@email.com` SUBJECT "subject"
All Modifiers - Any Order
MAIL TO 'a@a.com, b@b.com' SUBJECT 'test' HEADER 'X-Custom: value' TEXT BODY 'hello' CC 'c@c.com' BCC 'd@d.com' REPLY TO 'e@e.com' ATTACH '/root/file.pdf'
MAIL is a side-effect verb. It does not return a value and does not accept SET.

REDIRECT

REDIRECT performs an HTTP redirect. It accepts a relative path or a full URL. The default status code is 302. Use AS to specify a different code. REDIRECT ends the script - nothing after it executes.

Basic Redirect
REDIRECT '/dashboard'
With Status Code
REDIRECT '/login' AS '302'
Conditional Redirect
IF ?user IS NULL
OPEN
  REDIRECT 'https://ql.ocalt.com/login' AS '302'
CLOSE
Redirect After Operation
RUN authenticate WITH ?token SET ?valid
AFTER IF ?valid IS EMPTY
OPEN
  REDIRECT 'https://ql.ocalt.com/error' AS '302'
CLOSE
OR
OPEN
  REDIRECT '/success' AS '302'
CLOSE
REDIRECT ends script execution immediately. Any statements after a REDIRECT are unreachable, including statements in the same chain.