title:Status Update May 2022 date: 2022-05-03 18:00 tags: jmp.chat
I have worked more this month on polishing/cleaning up my currect records for opensmtpd. I am still finding more things to do, but I am satisified with current code base. It is starting to feel like I have less and less things to do.
I have also written some preleminary documentation. The OpenBSD folks’ man
smtpd.conf
’ is a work of art. Seriously go read it. I have shamelessly copied
numerous portions of that documentation to create my own monstrosity.
Whoever ends up committing my code for OpenBSD’s configuration for guix, will probably have to revise my rough draft of a document. But at least there is visible forward movement in the project. Here is that documentation that I was telling you about:
Apologies for the weird exported documentation...
OpenSMTPD is an easy-to-use mail transfer agent (MTA). Its configuration file is
throughly documented in man 5 smtpd.conf
. OpenSMTPD listens for incoming
mail and matches the mail to actions. The following records represent those
stages: <opensmtpd-listen-on-configuration>
,
<opensmtpd-listen-on-socket-configuration>=, =<opensmtpd-match-configuration>
,
<opensmtpd-action-local-delivery-configuration>
, and
<opensmtpd-action-relay-configuration>
.
Additionally, each <opensmtpd-listen-on-configuration>
and
<opensmtpd-listen-on-socket-configuration>
may use a list of
<opensmtpd-filter-configuration>
, and/or
<opensmtpd-filter-phase-configuration>
records to filter email/spam. Also
numerous records’ fieldnames use <opensmtpd-table-configuration>
to hold lists
or key value pairs of data.
A simple example configuration is below:
(let ((smtp.gnu.org (opensmtpd-pki-configuration
(domain "smtp.gnu.org")
(cert "file.cert")
(key "file.key"))))
(service opensmtpd-service-type
(opensmtpd-configuration
(listen-ons (list
(opensmtpd-listen-on-configuration
(pki smtp.gnu.org))
(opensmtpd-listen-on-configuration
(pki smtp.gnu.org)
(secure-connection "smtps"))))
(matches (list
(opensmtpd-match-configuration
(action
(opensmtpd-action-local-delivery-configuration
(name "local-delivery"))))
(opensmtpd-match-configuration
(action
(opensmtpd-action-relay-configuration
(name "relay")))))))))
Scheme Variable: opensmtpd-service-type
Service type for the OpenSMTPD (https://www.opensmtpd.org) email server. The
value for this service type is a <opensmtpd-configuration>
record.
Data Type: opensmtpd-configuration
Data type representing the configuration of OpenSMTPD.
package
(default: opensmtpd
)
The OpenSMTPD package to use.
config-file
(default: #f
)
File-like object of the OpenSMTPD configuration file to use. By default it
listens on the loopback network interface, and allows for mail from users
and daemons on the local machine, as well as permitting email to remote
servers. Run man smtpd.conf
for more information.
bounce
(default: (list "4h")
)
bounce
is a list of strings, which send warning messages to the envelope
sender when temporary delivery failures cause a message to remain in the
queue for longer than string delay. Each string delay parameter consists
of a string beginning with a positive decimal integer and a unit s, m, h,
or d. At most four delay parameters can be specified.
listen-ons
(default: (list (opensmtpd-listen-on-configuration))
)
listen-ons
is a list of <opensmtpd-listen-on-configuration>
records.
This list details what interfaces and ports OpenSMTPD listens on as well as
other information.
listen-on-socket
(default: (opensmtpd-listen-on-socket-configuration-configuration)
)
Listens for incoming connections on the Unix domain socket.
includes
(default: #f
)
includes
is a list of string filenames. Each filename’s contents is
additional configuration that is inserted into the top of the configuration
file.
matches
default:
(list (opensmtpd-match-configuration
(action (opensmtpd-action-local-delivery-configuration
(name "local")
(method "mbox")))
(for (opensmtpd-option-configuration
(option "for local"))))
(opensmtpd-match-configuration
(action (opensmtpd-action-relay-configuration
(name "outbound")))
(from (opensmtpd-option-configuration
(option "from local")))
(for (opensmtpd-option-configuration
(option "for any")))))
matches
is a list of <opensmtpd-match-configuration>
records, which
matches incoming mail and sends it to a correspending action. The match
records are evaluated sequentially, with the first match winning. If an
incoming mail does not match any match records, then it is rejected.
mta-max-deferred
(default: 100
)
When delivery to a given host is suspended due to temporary failures, cache at most number envelopes for that host such that they can be delivered as soon as another delivery succeeds to that host. The default is 100.
queue
(default: #f
)
queue
expects an <opensmtpd-queue-configuration>
record. With it, one may
compress and encrypt queue-ed emails as well as set the default expiration
time for temporarily undeliverable messages.
smtp
(default: #f
)
smtp
expects an <opensmtpd-smtp-configuration>
record, which lets one
specifiy how large email may be along with other settings.
srs
(default: #f
)
srs
expects an <opensmtpd-srs-configuration>
record, which lets one set
up SRS, the Sender Rewritting Scheme.
Data Type: opensmtpd-listen-on-configuration
Data type representing the configuration of an
<opensmtpd-listen-on-configuration>
. Listen on the fieldname interface
for
incoming connections, using the same syntax as for ifconfig(8). The interface
parameter may also be an string interface group, an string IP address, or a
string domain name. Listening can optionally be restricted to a specific
address fieldname family
, which can be either “inet4” or “inet6”.
interface
(default: “lo”)
The string interface to listen for incoming connections. These interface can
usually be found by the command ip link
.
family
(default: #f
)
The string IP family to use. Valid strings are “inet4” or “inet6”.
auth
(default: #f
)
Support SMTPAUTH: clients may only start SMTP transactions after successful
authentication. If auth
is #t
, then users are authenticated against
their own normal login credentials. Alternatively auth
may be an
<opensmtpd-table-configuration>
whose users are authenticated against
their passwords.
auth-optional
(default: #f
)
Support SMTPAUTH optionally: clients need not authenticate, but may do so.
This allows the <opensmtpd-listen-on-configuration>
to both accept
incoming mail from untrusted senders and permit outgoing mail from
authenticated users (using <opensmtpd-match-configuration>
fieldname
auth
). It can be used in situations where it is not possible to listen on
a separate port (usually the submission port, 587) for users to
authenticate.
filters
(default: #f
)
A list of one or many <opensmtpd-filter-configuration>
or
<opensmtpd-filter-phase-configuration>
records. The filters are applied
sequentially. These records listen and filter on connections handled by this
listener.
hostname
(default: #f
)
Use string “hostname” in the greeting banner instead of the default server name.
hostnames
(default: #f
)
Override the server name for specific addresses. Use a
<opensmtpd-table-configuration>
containing a mapping of string IP
addresses to hostnames. If the address on which the connection arrives
appears in the mapping, the associated hostname is used.
mask-src
(default: #f
)
If #t
, then omit the from part when prepending “Received” headers.
disable-dsn
(default: #f
)
When #t
, then disable the DSN (Delivery Status Notification) extension.
pki
(default: #f
)
For secure connections, use an <opensmtpd-pki-configuration>
to prove a mail server’s identity.
port
(default: #f
)
Listen on the integer port instead of the default port of 25.
proxy-v2
(default: #f
)
If #t
, then support the PROXYv2 protocol, rewriting appropriately source
address received from proxy.
received-auth
(default: #f
)
If #t
, then in “Received” headers, report whether the session was
authenticated and by which local user.
senders
(default: #f
)
Look up the authenticated user in the supplied
<opensmtpd-table-configuration>
to find the email addresses that user is
allowed to submit mail as.
secure-connection
(default: #f
)
This is a string of one of these options:
|----------------------+---------------------------------------------| | "smtps" | Support SMTPS, by default on port 465. | |----------------------+---------------------------------------------| | "tls" | Support STARTTLS, by default on port 25. | |----------------------+---------------------------------------------| | "tls-require-verify" | Like tls, but force clients to establish | | | a secure connection before being allowed to | | | start an SMTP transaction. With the verify | | | option, clients must also provide a valid | | | certificate to establish an SMTP session. | |----------------------+---------------------------------------------|
- `tag` (default: `#f`)
Clients connecting to the listener are tagged with the given string tag.
Data Type: opensmtpd-listen-on-socket-configuration
Data type representing the configuration of an
<opensmtpd-listen-on-socket-configuration>
. Listen for incoming SMTP
connections on the Unix domain socket /var/run/smtpd.sock
. This is done by
default, even if the directive is absent.
filters
(default: #f
)
A list of one or many <opensmtpd-filter-configuration>
or
<opensmtpd-filter-phase-configuration>
records. These filter incoming
connections handled by this listener.
mask-src
(default: #f
)
If #t
, then omit the from part when prepending “Received” headers.
tag
(default: #f
)
Clients connecting to the listener are tagged with the given string tag.
Data Type: opensmtpd-match-configuration
This data type represents the configuration of an
<opensmtpd-match-configuration>
record.
If at least one mail envelope matches the options of one match record, receive
the incoming message, put a copy into each matching envelope, and atomically
save the envelopes to the mail spool for later processing by the respective
<opensmtpd-action-configuration>
found in fieldname action
.
action
(default: #f
)
If mail matches this match configuration, then do this action. Valid values
include <opensmtpd-action-local-delivery-configuration>
or
<opensmtpd-action-relay-configuration>
.
options
(default: #f
) <opensmtpd-option-configuration>
The fieldname ’option’ is a list of unique
<opensmtpd-option-configuration>
records.
Each <opensmtpd-option-configuration>
record’s fieldname ’option’ has some
mutually exclusive options: there can be one “for” and one “from” option.
The following matching options are supported and can all be negated via (not #t). The options that support a table (anything surrounded with ’<’ and ’>’ eg:
for any
Specify that session may address any destination.
for local
Specify that session may address any local domain. This is the default, and may be omitted.
for domain _domain_ | <domain>
Specify that session may address the string or list table domain.
for rcpt-to _recipient_ | <recipient>
Specify that session may address the string or list table recipient.
from any
Specify that session may originate from any source.
from auth
Specify that session may originate from any authenticated user, no matter the source IP address.
from auth _user_ | <user>
Specify that session may originate from authenticated user or user list user, no matter the source IP address.
from local
Specify that session may only originate from a local IP address, or from the local enqueuer. This is the default, and may be omitted.
from mail-from _sender_ | <sender>
Specify that session may originate from sender or table sender, no matter the source IP address.
from rdns
Specify that session may only originate from an IP address that resolves to a reverse DNS.
from rdns _hostname_ | <hostname>
Specify that session may only originate from an IP address that resolves to a reverse DNS matching string or list string hostname.
from socket
Specify that session may only originate from the local enqueuer.
from src _address_ | <address>
Specify that session may only originate from string or list table address which can be a specific address or a subnet expressed in CIDR-notation.
auth
Matches transactions which have been authenticated.
auth _username_ | <username>
Matches transactions which have been authenticated for user or user list username.
helo _helo-name_ | <helo-name>
Specify that session’s HELO / EHLO should match the string or list table helo-name.
mail-from _sender_ | <sender>
Specify that transactions’s MAIL FROM should match the string or list table sender.
rcpt-to _recipient_ | <recipient>
Specify that transaction’s RCPT TO should match the string or list table recipient.
tag tag
Matches transactions tagged with the given tag.
tls
Specify that transaction should take place in a TLS channel.
Here is a simple example:
(opensmtpd-option-configuration
(not #t)
(regex #f)
(option "for domain")
(data (opensmtpd-table-configuration
(name "domain-table")
(data (list "gnu.org" "dismail.de")))))
The mail must NOT come from the domains gnu.org
or dismail.de
.
Data Type: opensmtpd-option-configuration
Data Type: opensmtpd-action-local-delivery-configuration
This data type represents the configuration of an
<opensmtpd-action-local-delivery-configuration>
record.
name
(default: #f
)
name
is the string name of the relay action.
method
(default: "mbox"
)
The email delivery option. Valid options are:
"mbox"
Deliver the message to the user’s mbox with mail.local(8).
"expand-only"
Only accept the message if a delivery method was specified in an aliases or .forward file.
"forward-only"
Only accept the message if the recipient results in a remote address after the processing of aliases or forward file.
<opensmtpd-lmtp-configuration>
Deliver the message to an LMTP server at
<opensmtpd-lmtp-configuration>
’s fieldname destination
. The location
may be expressed as string host:port or as a UNIX socket. Optionally,
<opensmtpd-lmtp-configuration>
’s fieldname rcpt-to
might be specified
to use the recipient email address (after expansion) instead of the local
user in the LMTP session as RCPT TO.
<opensmtpd-maildir-configuration>
Deliver the message to the maildir in
<opensmtpd-maildir-configuration>
’s fieldname pathname
if specified,
or by default to ~/Maildir
.
The pathname may contain format specifiers that are expanded before use (see the below section about Format Specifiers).
If <opensmtpd-maildir-configuration>
’s record fieldname junk
is #t
,
then message will be moved to the ‘Junk’ folder if it contains a positive
‘X-Spam’ header. This folder will be created under fieldname pathname
if
it does not yet exist.
<opensmtpd-mda-configuration>
Delegate the delivery to the <opensmtpd-mda-configuration>
’s fieldname
command
(type string) that receives the message on its standard input.
The command
may contain format specifiers that are expanded before use
(see Format Specifiers).
alias
(default: #f
)
Use the mapping table for aliases expansion. alias
is an
<opensmtpd-table-configuration>
.
ttl
(default: #f
)
ttl
is a string specify how long a message may remain in the queue. It’s
format is n{s|m|h|d}
. eg: “4m” is four minutes.
user
(default: #f
)
user
is the string username for performing the delivery, to be looked up
with getpwnam(3).
This is used for virtual hosting where a single username is in charge of handling delivery for all virtual users.
This option is not usable with the mbox delivery method.
userbase
(default: #f
)
userbase
is an <opensmtpd-table-configuration>
record for mapping user
lookups instead of the getpwnam(3) function.
The fieldnames user
and userbase
are mutually exclusive.
virtual
(default: #f
)
virtual
is an <opensmtpd-table-configuration>
record is used for virtual
expansion.
Data Type: opensmtpd-action-relay-configuration
This data type represents the configuration of an
<opensmtpd-action-relay-configuration>
record.
name
(default: #f
)
name
is the string name of the relay action.
backup
(default: #f
)
When #t
, operate as a backup mail exchanger delivering messages to any
mail exchanger with higher priority.
backup-mx
(default: #f
)
Operate as a backup mail exchanger delivering messages to any mail exchanger with higher priority than mail exchanger identified as string name.
helo
(default: #f
)
Advertise string heloname as the hostname to other mail exchangers during the HELO phase.
helo-src
(default: #f
)
Use the mapping <openmstpd-table-configuration>
to look up a hostname
matching the source address, to advertise during the HELO phase.
domain
(default: #f
)
Do not perform MX lookups but look up destination domain in an
<opensmtpd-table-configuration>
and use matching relay url as relay host.
host
(default: #f
)
Do not perform MX lookups but relay messages to the relay host described by
the string relay-url. The format for relay-url is
[proto://[label@]]host[:port]
. The following protocols are available:
Unless noted, port defaults to 25.
The label corresponds to an entry in a credentials table, as documented in
table(5)
. It is used with the "smtp+tls"
and "smtps"
protocols for
authentication. Server certificates for those protocols are verified by
default.
pki
(default: #f
)
For secure connections, use the certificate associated with
<opensmtpd-pki-configuration>
(declared in a pki directive) to prove the
client’s identity to the remote mail server.
srs
(default: #f
)
If #t
, then when relaying a mail resulting from a forward, use the Sender
Rewriting Scheme to rewrite sender address.
tls
(default: #f
) boolean or string “no-verify”
When #t
, Require TLS to be used when relaying, using mandatory STARTTLS by
default. When used with a smarthost, the protocol must not be
"smtp+notls://"
. When string "no-verify"
, then do not require a valid
certificate.
auth
(default: #f
) <opensmtpd-table-configuration>
Use the alist <opensmtpd-table-configuration>
for connecting to relay-url
using credentials. This option is usable only with fieldname host
option.
mail-from
(default: #f
) string
Use the string mailaddress as MAIL FROM address within the SMTP transaction.
src
(default: #f
) string | <opensmtpd-table-configuration>
Use the string or <opensmtpd-table-configuration>
sourceaddr for the
source IP address, which is useful on machines with multiple interfaces. If
the list contains more than one address, all of them are used in such a way
that traffic is routed as efficiently as possible.
Data Type: opensmtpd-filter-configuration
This data type represents the configuration of an
<opensmtpd-filter-configuration>
. This is the filter record one should use
if they want to use an external package to filter email eg: rspamd or
spamassassin.
name
(default: #f
)
The string name of the filter.
proc
(default: #f
)
The string command or process name. If proc-exec
is #t
, proc
is
treated as a command to execute. Otherwise, it is a process name.
proc-exec
(default: #f
)
Data Type: opensmtpd-filter-phase-configuration
This data type represents the configuration of an
<opensmtpd-filter-phase-configuration>
.
In a regular workflow, smtpd(8) may accept or reject a message based only on the content of envelopes. Its decisions are about the handling of the message, not about the handling of an active session.
Filtering extends the decision making process by allowing smtpd(8) to stop at each phase of an SMTP session, check that options are met, then decide if a session is allowed to move forward.
With filtering via an <opensmtpd-filter-phase-configuration>
record, a
session may be interrupted at any phase before an envelope is complete. A
message may also be rejected after being submitted, regardless of whether the
envelope was accepted or not.
name
(default: #f
)
The string name of the filter phase.
phase-name
(default: #f
)
The string name of the phase. Valid values are:
options
(default #f
)
A list of unique <opensmtpd-option-configuration>
records.
At each phase, various options, specified by a list of
<opensmtpd-option-configuration>
, may be checked. The
<opensmtpd-option-configuration>
’s fieldname ’option’ values of: “fcrdns”,
“rdns”, and “src” data are available in all phases, but other data must have
been already submitted before they are available. Options with a <table>
next to them require the <opensmtpd-option-configuration>
’s fieldname
data
to be an <opensmtpd-table-configuration>
. There are the available
options:
These conditions may all be negated by setting
<opensmtpd-option-configuration>
’s fieldname not
to #t
.
Any conditions that require a table may indicate that tables include regexs
setting <opensmtpd-option-configuration>
’s fieldname regex
to #t
.
decision
A string decision to be taken. Some decisions require an message
or
value
. Valid strings are:
Decisions that involve a message require that the message be RFC valid, meaning that they should either start with a 4xx or 5xx status code. Descisions can be taken at any phase, though junking can only happen before a message is committed.
message
(default #f
)
A string message beginning with a 4xx or 5xx status code.
value
(default: #f
)
A number value. value
and message
are mutually exclusive.
Data Type: opensmtpd-option-configuration
This data type represents the configuration of an
<opensmtpd-option-configuration>
, which is used by
<opensmtpd-filter-phase-configuration>
and <opensmtpd-match-configuration>
to match various options for email.
conditition
(default #f
)
A string option to be taken. Some options require a string or an
<opensmtpd-table-configuration>
via the fieldname data. When the option
record is used inside of an <opensmtpd-filter-phase-configuration>
, then
valid strings are:
At each phase, various options may be matched. The fcrdns, rdns, and src data are available in all phases, but other data must have been already submitted before they are available.
When <opensmtpd-option-configuration>
is used inside of an
<opensmtpd-match-configuration>
, then valid strigs for fieldname option
are: “for”, “for any”, “for local”, “for domain”, “for rcpt-to”, “from any”
“from auth”, “from local”, “from mail-from”, “from rdns”, “from socket”,
“from src”, “auth”, “helo”, “mail-from”, “rcpt-to”, “tag”, or “tls”.
data
(default #f
) <opensmtpd-table-configuration>
Some options require a table to be present. One would specify that table here.
regex
(default: #f
) boolean
Any options using a table may indicate that tables hold regex by prefixing the table name with the keyword regex.
not
(default: #f
) boolean
When #t
, this option record is negated.
Data Type: opensmtpd-table-configuration
This data type represents the configuration of an
<opensmtpd-table-configuration>
.
name
(default #f
)
name
is the name of the <opensmtpd-table-configuration>
record.
data
(default: #f
)
data
expects a list of strings or an alist, which is a list of
cons cells. eg: (data (list ("james" . "password")))
OR
(data (list ("gnu.org" "fsf.org")))
.
Data Type: opensmtpd-pki-configuration
This data type represents the configuration of an
<opensmtpd-pki-configuration>
.
domain
(default #f
)
domain
is the string name of the <opensmtpd-pki-configuration>
record.
cert
(default: #f
)
cert
(default: #f
)
cert
is the string certificate filename to use for this pki.
key
(default: #f
)
key
is the string certificate falename to use for this pki.
dhe
(default: "none"
)
Specify the DHE string parameter to use for DHE cipher suites with host pkiname. Valid parameter values are “none”, “legacy”, or “auto”. For “legacy”, a fixed key length of 1024 bits is used, whereas for “auto”, the key length is determined automatically. The default is “none”, which disables DHE cipher suites.
Data Type: opensmtpd-maildir-configuration
pathname
(default: "~/Maildir"
)
Deliver the message to the maildir if pathname if specified, or by default
to ~/Maildir
.
The pathname may contain format specifiers that are expanded before use (see FORMAT SPECIFIERS).
junk
(default: #f
)
If the junk argument is #t
, then the message will be moved to the ‘Junk’
folder if it contains a positive ‘X-Spam’
header. This folder will be
created under pathname if it does not yet exist.
Data Type: opensmtpd-mda-configuration
name
The string name for this MDA command.
command
Delegate the delivery to a command that receives the message on its standard input.
The command may contain format specifiers that are expanded before use (see FORMAT SPECIFIERS).
Data Type: opensmtpd-queue-configuration
compression
(default #f
)
Store queue files in a compressed format. This may be useful to save disk space.
encryption
(default #f
)
Encrypt queue files with EVPaes256gcm(3). If no key is specified, it is read with getpass(3). If the string stdin or a single dash (‘-’) is given instead of a key, the key is read from the standard input.
ttl-delay
(default #f
)
Set the default expiration time for temporarily undeliverable messages, given as a positive decimal integer followed by a unit s, m, h, or d. The default is four days (“4d”).
Data Type: opensmtpd-smtp-configuration
Data type representing an <opensmtpd-smtp-configuration>
record.
ciphers
(default: #f
)
Set the control string for SSLCTXsetcipherlist(3). The default is
“HIGH:!aNULL:!MD5”.
limit-max-mails
(default: 100
)
Limit the number of messages to count for each sessio
limit-max-rcpt
(default: 1000
)
Limit the number of recipients to count for each transaction.
max-message-size
(default: 35M
)
Reject messages larger than size, given as a positive number of bytes or as a string to be parsed with scanscaled(3).
sub-addr-delim character
(default: +
)
When resolving the local part of a local email address, ignore the ASCII
character and all characters following it. This is helpful for email
filters. "admin+bills@gnu.org"
is the same email address as
"admin@gnu.org"
. BUT an email filter can filter emails addressed to first
email address into a ’Bills’ email folder.
Data Type: opensmtpd-srs-configuration
key
(default: #f
)
Set the secret key to use for SRS, the Sender Rewriting Scheme.
backup-key
(default: #f
)
Set a backup secret key to use as a fallback for SRS. This can be used to implement SRS key rotation.
ttl-delay
(default: "4d"
)
Set the time-to-live delay for SRS envelopes. After this delay, a bounce reply to the SRS address will be discarded to limit risks of forged addresses.
Format Specifiers
Some configuration records support expansion of their parameters at
runtime. Such records (for example
<opensmtpd-maildir-configuration>
, <opensmtpd-mda-configuration>
) may use
format specifiers which are expanded before delivery or relaying. The
following formats are currently supported:
Expansion formats also support partial expansion using the optional bracket notations
with substring offset. For example, with recipient domain “example.org”
:
In addition, modifiers may be applied to the token. For example, with recipient
“User+Tag@Example.org”
: