Sends an email through SMTP.
This function is exported by the KS module.
Mail(Recipients, Subject, Message , Options)
One address, or an Array of them. An empty Array, an empty address, or an entry which is not a String is an error.
Type: String
The message subject.
Type: String
The message body.
Type: Map
| Key | Value |
|---|---|
host | Required. The server as hostname or hostname:port. Port 25 if none is given. A bracketed IPv6 literal keeps its own colons. |
from | Required. The sender's address. |
cc | A further recipient, or an Array of them. |
bcc | A blind-copy recipient, or an Array of them. These reach the server but do not appear in the message headers. |
replyto | The address replies should go to, when it differs from from. |
attachments | A file path, or an Array of them. A path which cannot be read is an error. |
headers | A Map of additional SMTP header names and values. |
An option which takes exactly one value — host, from, replyto — also accepts a one-element Array.
This function returns an empty string, and returns only once the server has accepted the message.
| Thrown | When |
|---|---|
| TypeError | Recipients is neither a String nor an Array of them, or Options is not a Map. |
| ValueError | A 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. |
| OSError | An 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. |
#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.