Email Message
Creating and configuring email messages
email-message
Creates a new empty email message object that can be configured with headers, body, and attachments.
(none)
returns native gomail-message object for building email content
msg: email-message
equal { msg |type? } 'native
gomail-message//Set-header
Sets a standard email header field such as Subject, To, From, Cc, or Bcc with the specified value.
message Native gomail-message object
field String or Tagword representing header name (e.g., "Subject", 'to, 'from)
value String or Email containing the header value
returns the message object for method chaining
msg: email-message
msg .Set-header "Subject" "Test Email"
msg .Set-header 'to "user@example.com"
error { msg .Set-header "Subject" 123 }
gomail-message//Set-address-header
Sets an email address header with both email address and display name, commonly used for From, To, Cc, and Bcc fields.
message Native gomail-message object
field String header field name (e.g., "From", "To", "Cc", "Bcc")
address String email address
name String display name for the email address
returns the message object for method chaining
gomail-message//Set-body
Sets the main body content of the email with the specified MIME content type, supporting plain text and HTML formats.
message Native gomail-message object
contentType String MIME content type (e.g., "text/plain", "text/html")
content String containing the email body content
returns the message object for method chaining
gomail-message//Attach
Attaches a file to the email message using a file URI, making the file available as an email attachment.
message Native gomail-message object
file Uri pointing to the file to attach (must use file
returns the message object for method chaining
gomail-message//Add-alternative
Adds alternative content to the email (e.g., HTML version alongside plain text), allowing email clients to choose their preferred format.
message Native gomail-message object
contentType String MIME content type for the alternative content
content String containing the alternative body content
returns the message object for method chaining
new-email-dialer
Creates a new SMTP dialer configured with server details and authentication credentials for sending emails.
server String SMTP server hostname (e.g., "smtp.gmail.com", "mail.example.com")
port Integer SMTP port number (commonly 25, 465, 587, or 2525)
username String username for SMTP authentication
password String password for SMTP authentication
returns native gomail-dialer object configured for sending emails
gomail-dialer//Dial-and-send
Connects to the SMTP server and sends the specified email message, handling authentication and delivery.
dialer Native gomail-dialer object configured with SMTP settings
message Native gomail-message object containing the email to send
returns the dialer object on success, or error object if sending fails
Email parsing functions
reader//Parse-email
Parses email data from a reader.
reader native reader object containing email data
returns native parsed-email object
equal { reader %email.eml |parse-email |type? } 'native
equal { reader %email.eml |parse-email |kind? } 'parsed-email
parsed-email//Subject?
Gets the subject from a parsed email.
email native parsed-email object
returns string containing the email subject
equal { reader %email.eml |parse-email |subject? |type? } 'string
parsed-email//Message-id?
Gets the message ID from a parsed email.
email native parsed-email object
returns string containing the email message ID
equal { reader %email.eml |parse-email |message-id? |type? } 'string
parsed-email//Html-body?
Gets the HTML body from a parsed email.
email native parsed-email object
returns string containing the HTML body of the email
equal { reader %email.eml |parse-email |html-body? |type? } 'string
parsed-email//Text-body?
Gets the plain text body from a parsed email.
email native parsed-email object
returns string containing the plain text body of the email
equal { Reader %email.eml |parse-email |text-body? |type? } 'string
parsed-email//Attachments?
Gets the attachments from a parsed email.
email native parsed-email object
returns native object containing email attachments
parsed-email//Embedded-files?
Gets the embedded files from a parsed email.
email native parsed-email object
returns native object containing embedded files from the email
Imap client
imap-client
Create new IMAP client connection with username, password, server, and port.
username String - IMAP username
password String - IMAP password
server String - IMAP server hostname (e.g., "imap.gmail.com")
port Integer - IMAP server port (usually 993 for SSL, 143 for plain)
returns Native imap-client object on successError on connection failure
imap-client\oauth2
Create new IMAP client connection with OAuth2 authentication (email, access_token, server, port).
email String - Email address for OAuth2 authentication
access_token String - OAuth2 access token
server String - IMAP server hostname (e.g., "imap.gmail.com")
port Integer - IMAP server port (usually 993 for SSL)
returns Native imap-client object on successError on connection failure
imap-client//Select-folder
Select a folder for operations (e.g., 'INBOX').
client Native imap-client object
folder String - Folder name (e.g., "INBOX", "Sent", "Drafts")
returns Native imap-client object (for method chaining)Error if folder selection fails
imap-client//Get-folders
Get list of available folders.
client Native imap-client object
returns Block of strings containing folder names (e.g., ["INBOX", "Sent", "Drafts"])Error if retrieval fails
imap-client//Search-emails
Search for emails using IMAP search criteria (e.g., 'UNSEEN', 'FROM "user@domain.com"', 'SUBJECT "test"').
client Native imap-client object
search_criteria String - IMAP search criteria (e.g., "UNSEEN", "FROM "user@domain.com"", "SUBJECT "test"", "SINCE "01-Jan-2023"")
returns Block of integers containing matching email UIDsError if search fails
imap-client//Get-overviews
Get email overviews (headers only, fast) for given UIDs block.
client Native imap-client object
uids Block of integers containing email UIDs to fetch overviews for
returns Block of dictionaries with email overview information (uid, subject, from, to, date, size, flags)Error if retrieval fails
imap-client//Get-emails
Get full emails with bodies and attachments (slower) for given UIDs block.
client Native imap-client object
uids Block of integers containing email UIDs to fetch full content for
returns Block of dictionaries with complete email information (uid, subject, from, to, cc, bcc, date, received, message-id, size, text, html, flags, attachments)Error if retrieval fails
SMTP Server Functions
Creating and running SMTP mail servers.
smtp-server
Creates a new SMTP server that can receive incoming email messages on the specified address.
address String containing the server address (e.g., "
returns native smtpd object configured to listen on the specified address
smtp-server 2525 |type?
; returns native
smtp-server ":2525" |kind?
; returns smtpd
smtpd//Serve
Starts the SMTP server listening for incoming emails and calls the handler function for each received message.
server Native smtpd object created by smtp-server
handler Function that processes incoming emails (reader from to origin -> ...)
appname String name for the SMTP server application
password String password for SMTP authentication (empty string for no auth)
returns the server object after starting to listen, or error if unable to serve
handler: fn { reader from to origin } { print "Got email from:" from }
smtp-server ":2525"
|Serve handler "TestSMTP" ""
MQTT Client Functions
mqtt-uri//Open
Opens a connection to an MQTT broker.
uri MQTT broker URI (format
returns native MQTT client connection (type: "mqtt-client")error if connection fails
mqtt-client//Disconnect
Disconnects from the MQTT broker.
client MQTT client connection (type
returns integer 1 for successerror if disconnection fails
mqtt-client//Publish
Publishes a message to an MQTT topic with specified QoS and retain flag.
client MQTT client connection (type
topic Topic to publish to (string)
payload Message payload (string)
qos Quality of Service level (integer 0, 1, or 2)
retain Whether message should be retained (boolean)
returns integer 1 for successerror if publish fails
mqtt-client//Publish-simple
Publishes a message to an MQTT topic with default settings (QoS 0, no retain).
client MQTT client connection (type
topic Topic to publish to (string)
payload Message payload (string)
returns integer 1 for success (uses QoS 0, no retain)error if publish fails
mqtt-client//Subscribe
Subscribes to an MQTT topic with a message handler function.
client MQTT client connection (type
topic Topic pattern to subscribe to (string, can include wildcards)
qos Quality of Service level (integer 0, 1, or 2)
handler Callback function to handle received messages
returns integer 1 for successerror if subscription fails
mqtt-client//Subscribe-simple
Subscribes to an MQTT topic with default QoS 0 and a message handler function.
client MQTT client connection (type
topic Topic pattern to subscribe to (string)
handler Callback function to handle received messages
returns integer 1 for success (uses QoS 0)error if subscription fails
mqtt-client//Unsubscribe
Unsubscribes from an MQTT topic.
client MQTT client connection (type
topic Topic to unsubscribe from (string)
returns integer 1 for successerror if unsubscription fails
mqtt-client//Is-connected
Checks if the MQTT client is currently connected to the broker.
client MQTT client connection (type
returns integer 1 if connected, 0 if not connected
mqtt-options
Creates a new MQTT client options object for advanced configuration.
returns new MQTT client options object (type: "mqtt-options")
mqtt-options//Set-broker
Sets the MQTT broker address in the options.
options MQTT options object (type
broker Broker URI string
returns the same options object (for method chaining)
mqtt-options//Set-client-id
Sets the client ID in the MQTT options.
options MQTT options object (type
client-id Client identifier string
returns the same options object (for method chaining)
mqtt-options//Set-keep-alive
Sets the keep alive interval in seconds.
options MQTT options object (type
seconds Keep alive interval in seconds (integer)
returns the same options object (for method chaining)
mqtt-options//Set-username
Sets the username for MQTT authentication.
options MQTT options object (type
username Username string for MQTT authentication
returns the same options object (for method chaining)
mqtt-options//Set-password
Sets the password for MQTT authentication.
options MQTT options object (type
password Password string for MQTT authentication
returns the same options object (for method chaining)
mqtt-options//Set-will
Sets the Last Will and Testament message with QoS and retain flag.
options MQTT options object (type
topic Will topic string
payload Will message payload string
qos Quality of Service level for will message (integer 0, 1, or 2)
retain Whether will message should be retained (integer 0 = false, 1 = true)
returns the same options object (for method chaining)
mqtt-options//Connect-with-options
Creates and connects an MQTT client using the configured options.
options MQTT options object (type
returns native MQTT client connection (type: "mqtt-client")error if connection fails