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.
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
MAIL TEXT BODY 'hello world' TO 'email@email.com' SUBJECT 'this is a subject'
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.
MAIL TEXT BODY 'hello' TO 'email@email.com, email@email.co' SUBJECT 'multi recipient'
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
MAIL HTML BODY '<p>Your quote is attached.</p>' HEADER 'From: Sales <sales@yourdomain.com>' TO 'client@site.com' SUBJECT 'Your quote'
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.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.
MAIL TEXT BODY 'help needed' TO 'support@site.com' SUBJECT 'support' REPLY TO 'user@site.com'
MAIL TEXT BODY 'see attached' TO 'client@site.com' SUBJECT 'invoice' ATTACH '/root/invoice.pdf'
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:
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.
MAIL HTML BODY "hello" HEADER 'From: sender@site.com' TO `email@email.com` SUBJECT "subject"
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'
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.
REDIRECT '/dashboard'
REDIRECT '/login' AS '302'
IF ?user IS NULL
OPEN
REDIRECT 'https://ql.ocalt.com/login' AS '302'
CLOSE
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 are unreachable, including statements in the same chain.