Basic configuration

Listen and serve

First of all, create the file /etc/vsmtp/vsmtp.toml with this content:

version_requirement = ">=1.3.0"

# root domain of the server.
domain = ""

# addresses that the server will listen to.
# (change `` for the address you want to listen to)
addr = [""]
addr_submission = [""]
addr_submissions = [""]

The server can now listen and serve SMTP connections.

$> sudo systemd restart vsmtp
$> telnet
220 Service ready
554 permanent problems with the remote server

By default, the server will deny any connection. We have to define rules to accept connections and filter messages.

Define filtering logics

We will configure these rules:

  • Messages from blacklisted domain will be rejected.
  • As Jenny is 11 years old, Jane wants a blind copy of her daughter messages.
  • Messages sent to the family must be delivered in MailBox format.

First, let’s define all the required objects for John Doe’s MTA.

Create the /etc/vsmtp/rules/objects.vsl file with the content:

// -- /etc/vsmtp/rules/objects.vsl
// IP addresses of the MTA and the internal IP range.
object local_mta ip4 = "";
object internal_net rg4 = "";

// Doe's family domain name.
object family_domain fqdn = "";

// Mailboxes.
object john address = "";
object jane address = "";
object jimmy address = "";
object jenny address = "";

// A group to manipulate mailboxes.
object family_addr group = [john, jane, jimmy, jenny];

// Quarantine folders.
object unknown_quarantine string = "doe/bad_user";
object virus_queue string = "doe/virus";

// A user blacklist file.
object blacklist file:fqdn = "blacklist.txt";

The content of the blacklist.txt file is:


And create the /etc/vsmtp/rules/main.vsl file with the content:

// -- /etc/vsmtp/rules/main.vsl
// Import the object file. The 'doe' prefix is an alias.
import "objects" as doe;

  // List of rules execute after receiving "MAIL FROM" from a client.
  // At this stage the sender is known and can be accessed using `mail_from()`.
  mail: [
    // Deny any sender with a domain listed in the `blacklist` group.
    rule "blacklist" || {
      if mail_from().domain in doe::blacklist { deny() } else { next() }

  // List of rules execute after receiving "RCPT TO" from a client.
  // The current recipient can be inspected using `rcpt()`.
  rcpt: [
    // automatically set Jane as a BCC if Jenny is part of the recipients.
    action "bcc jenny" || if rcpt() is doe::jenny { bcc(doe::jane) },

  // The deliver stage is executed just before vsmtp delivers the message.
  deliver: [
    action "setup delivery" || {
      // if a recipient is part of the family, we deliver the email locally.
      // Otherwise, we just deliver the email to another server.
      for rcpt in rcpt_list() {
        if rcpt in doe::family_addr { maildir(rcpt) } else { deliver(rcpt) }

Add these lines to your /etc/vsmtp/vsmtp.toml:

# ...

# entry point for our rules.
filepath = "/etc/vsmtp/rules/main.vsl"

Restart the server to apply the rules.