Mail

Sends an email through SMTP.

This function is exported by the KS module.

Mail(Recipients, Subject, Message , Options)

Parameters

Recipients

Type: String or Array

One address, or an Array of them. An empty Array, an empty address, or an entry which is not a String is an error.

Subject

Type: String

The message subject.

Message

Type: String

The message body.

Options

Type: Map

KeyValue
hostRequired. The server as hostname or hostname:port. Port 25 if none is given. A bracketed IPv6 literal keeps its own colons.
fromRequired. The sender's address.
ccA further recipient, or an Array of them.
bccA blind-copy recipient, or an Array of them. These reach the server but do not appear in the message headers.
replytoThe address replies should go to, when it differs from from.
attachmentsA file path, or an Array of them. A path which cannot be read is an error.
headersA Map of additional SMTP header names and values.

An option which takes exactly one value — host, from, replyto — also accepts a one-element Array.

Return Value

This function returns an empty string, and returns only once the server has accepted the message.

Errors

ThrownWhen
TypeErrorRecipients is neither a String nor an Array of them, or Options is not a Map.
ValueErrorA required option is missing, an option's value has the wrong shape, an address or port cannot be parsed, or a key is not recognized.
OSErrorAn attachment cannot be read, or the server rejects the message or cannot be reached. The server's own reason is included where it gave one.

Examples

#Import "Ks" { Mail }

Mail("someone@example.com", "Build finished", "The nightly build is done.",
    Map("host", "smtp.example.com:25",
        "from", "builds@example.com",
        "cc", ["lead@example.com", "qa@example.com"],
        "attachments", A_ScriptDir "\build.log"))

Note: The connection is unauthenticated and unencrypted, so the server must accept mail from the script's machine without a login.