KScript docs
EN

Mail: KScript.Mail

Configuration

Mail settings live under mail in the config section of kscript.json:

JSON
{
  "config": {
    "mail": {
      "driver": "smtp",
      "host": "smtp.example.com",
      "port": 587,
      "username": "shop",
      "from": { "address": "hello@example.com", "name": "The Shop" }
    }
  }
}
Setting What it does
driver log (the default) writes each message to the log. smtp sends it to a mail server. fake sends nothing and keeps it, as @fake_mail() does.
host, port The SMTP server. The defaults are localhost and 587.
username, password The SMTP sign-in. Leave the password out of kscript.json: it is read from the MAIL_PASSWORD environment variable (and the username from MAIL_USERNAME) when they aren't set here.
encryption tls (the default) upgrades the connection with STARTTLS. none sends in the clear, for a test server on your own computer.
from Who mail comes from unless @send_mail says: "hello@example.com", "The Shop <hello@example.com>", or { "address": ..., "name": ... }.
queue The queue queued mail goes on. Defaults to default.

As with every config setting, kscript.<env>.json can change them for one environment. A kscript.test.json with "driver": "fake" keeps tests from sending anything, and config.kscript can read the server from environment variables:

<fn name="configure" params="environment: string">
  <return value="{
      mail: {
        driver: 'smtp'
        host: @env('MAIL_HOST', default: 'localhost')
        port: @env('MAIL_PORT', default: '587')
      }
    }" />
</fn>
fn configure(environment: string) {
  return {
    mail: {
      driver: 'smtp'
      host: @env('MAIL_HOST', default: 'localhost')
      port: @env('MAIL_PORT', default: '587')
    }
  }
}