Objects

Objects are used to create reusable configuration variables declared using Rhai functions.

TypeDescriptionSyntaxComments
ip4IPv4 addressx.y.z.tDecimal values.
ip6IPv6 addressa:b:c:d:e:f:g:hHex values.
rg4IPv4 networkx.y.z.t/rgDecimal values.
rg6IPv6 prefixa:b:c:d:e:f:g:h/rgHex values.
addressEmail addressidentifier@fqdnString.
identifierLocal part of an addressuserString.
fqdnFully qualified domain namemy.domain.comString.
regexRegular expressionPERL regular expression.
fileA file of objectsUnix fileSee file section.
codea custom smtp codeSee code section.

All available objects types

Creating objects

Objects can be created via associated functions:

const my_ipv4 = ip4("127.0.0.1");
const my_address = address("john.doe@example.com");
// ...

Declaring objects in scripts

See the Object reference to get an extensive list of objects constructors.

Modules

It is recommended to declare objects inside .vsl files and importing them via the import Rhai directive in rule files.

See the Rhai modules documentation for more details.

// Object are accessible trough `import` when declared with the `export` keyword.
export const localhost = ip4("127.0.0.1");

An object file, `objects/network.vsl`

import "objects/network" as network;

#{
  connect: [
    rule "force accept localhost" || {
      if ctx::client_ip() == network::localhost {
        state::faccept();
      } else {
        state::next()
      }
    }
  ]
}

A rule in `filter.vsl`

Objects should be stored inside the objects directory of /etc/vsmtp if they are used into multiple rules sets.

/etc/vsmtp
  ┣ vsmtp.vsl
  ┣ filter.vsl
  ┣ conf.d/
  ┃     ┗ config.vsl
  ┣ domain-available/
  ┃     ┗ example.com/
  ┃       ┗ ...
  ┣ domain-enabled/
  ┃     ┗ example.com -> ...
  ┗ objects/
+       ┗ network.vsl

Placing objects files in `/etc/vsmtp/objects/`

However, if objects are used in only a specific rule set, they should be stored directly in a separate file among the rule set.

/etc/vsmtp
  ┣ vsmtp.vsl
  ┣ filter.vsl
  ┣ conf.d/
  ┃     ┗ config.vsl
  ┣ domain-available/
  ┃     ┗ example.com/
+ ┃        ┣ network-objects.vsl
  ┃        ┣ incoming.vsl
  ┃        ┣ outgoing.vsl
  ┃        ┗ internal.vsl
  ┣ domain-enabled/
  ┃     ┗ example.com -> ...
  ┗ objects/
-       ┗ network.vsl

Placing objects relative to a domain, renaming it to network-objects.vsl to make it clear that it is an object file

Grouping objects

Objects can be grouped using Rhai Arrays.

const authorized_users = [
  address("admin@example.com"),
  address("foo@example.com"),
  address("bar@example.com"),
];

An array of email address

When used with check operators (==, !=, in etc …), the whole array will be tested. The test stops when one element of the group matches, or nothing matches.

Different types of objects can be grouped together.

Pre-defined objects

vSL already exposes some objects. Check out the Variable reference to get more details.