Mail Module

The Mail Module is a native stack of mail services integrated into Libre Workspace, including Postfix (MTA), Dovecot (IMAP/LMTP), and SnappyMail (Webmail) running behind the Caddy reverse proxy.

It provides secure mailboxes and outgoing delivery, integrated directly with the workspace identity provider.

Architecture

The Mail Module is installed locally on the client instance but routes outgoing mail through the Central MTA:

  • Samba AD LDAP Integration: Dovecot and Postfix bind to the local Samba AD-DC via LDAP. This enables users to log into Webmail or IMAP clients using their standard domain credentials. Virtual mailbox paths and aliases are resolved directly via LDAP database queries.

  • Smart-Host Outbound Relay: Local Postfix is configured to route all outgoing emails to the Central MTA (smart-host) on port 587. It uses unique, instance-specific SASL credentials to authenticate against the Central MTA.

  • DKIM Signing and Rate Limits: All outbound emails are signed with DKIM keys and rate-limited on the Central MTA, protecting the IP reputation of the service. Without a Central MTA (standalone mode) the instance signs locally with OpenDKIM, using one key per domain.

Admin and User Portal Functions

Administrators and users can configure their email experiences directly in the Libre Workspace portal interface: * Allowed Senders Quota: Administrators can add, edit, or delete registered allowed sender addresses. These are synchronized dynamically with the Central MTA database using REST API calls with the client instance API key. The quota limit (maximum allowed senders) is enforced by the Central MTA based on the workspace flavor. * SnappyMail Webmail: Users can access the webmail interface at webmail.your-domain.org to read and send messages, change personal mailbox settings, and organize emails.

Email Client Setup and TLS

Postfix and Dovecot use the same Let’s Encrypt certificate as the webmail (webmail.your-domain.org); it is renewed automatically. Configure mail clients as follows (the page Mail → Client configuration shows the values for your instance):

  • Server: webmail.your-domain.org (the primary domain of the instance, also for mailboxes of additional mail domains)

  • IMAP: port 993 (SSL/TLS)

  • SMTP: port 465 (SSL/TLS) or 587 (STARTTLS)

  • Username: your full email address

Unencrypted logins are refused. Instances are reachable via IPv6. For IPv4-only networks see IPv4 access behind a reverse proxy below: IMAPS (993) and SMTPS (465) then also work over IPv4 with the same settings; port 587 (STARTTLS) stays IPv6 only.

IPv4 access behind a reverse proxy

Instances that are hosted behind an IPv4 entry host are only reachable over IPv6 directly. The entry host forwards IMAPS (993) and SMTPS (465) by the TLS server name (SNI) webmail.<domain> (for example Caddy with the layer4 module), so mail programs need no special settings and get the normal certificate.

  • Set MAIL_IPV4_PROXY="<address> [<address> ...]" in /etc/libre-workspace/libre-workspace.conf: the addresses the entry host connects from (IPv4 or IPv6, a /prefix is optional). Then run bash /usr/lib/libre-workspace/modules/mail/lib/apply_config.sh after removing /var/lib/libre-workspace/mail/config-version (or wait for the next update). Without the variable nothing changes.

  • The module then opens two additional ports, 10993 (IMAPS) and 10465 (SMTPS), that expect the PROXY protocol (version 2). Postfix, Dovecot and Fail2ban therefore see the real address of the mail program, not the address of the proxy. Direct clients keep using 993 and 465.

  • Only the proxy may reach 10993 and 10465 (security group / firewall). Dovecot checks the sender of the PROXY header (haproxy_trusted_networks), Postfix does not: anyone who can connect could claim a false client address.

  • Brute-force protection: a firewall ban cannot work for these connections (every packet comes from the proxy), so Fail2ban also writes banned addresses to two block lists. Postfix rejects them on port 10465 right at the connection (554 Client host rejected, /etc/postfix/libre-banned-clients). Dovecot refuses every login from them, also with the correct password (/etc/dovecot/libre-banned-clients, addresses hex encoded). Direct clients on 993/465 are blocked by the firewall as before.

  • Port 25 is not proxied: the central MTA delivers over IPv6 directly.

  • lib/selftest.sh checks the listeners and, with the proxy configured, that webmail.<domain> ports 993 and 465 answer on the public IPv4 address with a valid certificate.

Mail Domains

An instance can receive and send mail for several domains. Administrators manage them in the portal under Mail → Mail domains. Changes apply immediately, no restart is needed:

  1. Add the domain. In cloud mode it is registered at the Central MTA automatically.

  2. Open the DNS page of the domain and create the shown records: MX, SPF, DKIM and DMARC. The page checks whether they are published correctly.

  3. Create mailboxes or aliases with an address of the new domain.

The primary domain of the instance cannot be removed. A domain can only be removed while no mailbox address or alias uses it.

Creating Mailing Lists

To create a mailing list (distribution list) for mail accounts within the same Libre Workspace instance, you do not need external mailing list software. Instead, you can leverage Active Directory’s proxy addresses:

  1. Identify the email address for the mailing list (e.g., team@your-domain.org).

  2. For each user who should belong to the mailing list, add the value smtp:team@your-domain.org (or SMTP:team@your-domain.org) to their proxyAddresses LDAP attribute in the Samba AD-DC.

  3. When Postfix receives a message addressed to team@your-domain.org, it queries the LDAP database using virtual-alias-maps.cf.

  4. The LDAP query searches for all user objects containing that address in their proxyAddresses attribute and resolves it to their respective mail attributes.

  5. Postfix then automatically delivers a copy of the email to each member’s mailbox.

Brute-force protection

Fail2ban watches failed IMAP and SMTP logins. A client with 5 failed logins within 10 minutes is blocked for one hour on the mail ports (IPv4 and IPv6). Dovecot additionally refuses logins from it, which also covers connections through the IPv4 proxy. Banned addresses can be listed with fail2ban-client status libre-mail-dovecot and libre-mail-postfix and released with fail2ban-client unban <ip>.

Spam

Incoming mail is checked by the spam filter of the central MTA. Mail it considers spam gets the header X-Spam: Yes and is filed into the Junk folder. This happens before the user’s own filter rules, so spam is neither forwarded nor answered by the auto reply. The central MTA also asks the instance whether a recipient exists and rejects mail to unknown addresses right away; an address that was just created can still be rejected for up to about 10 minutes if mail was sent to it before.

Teaching the spam filter

With a central MTA, users can help the filter to learn:

  • Move the mail: into Junk means “this is spam”, out of Junk (not into the trash) means “this is wanted”. This works in every mail program and in the webmail. Moving it back within 10 minutes takes the report back.

  • Send it to spam@your-domain.org or nospam@your-domain.org, attached to your mail (Thunderbird: Message → Forward As → Attachment). A normal forward is not processed, you get an answer explaining this. Only users of the server can write to these addresses. If one of them is already used by a user or group, it stays theirs.

Privacy: a reported mail is sent completely to the central MTA. Only mails received through the MTA in the last 30 days are sent, never internal or own mails. The MTA stores a checksum of the mail, not its content; the filter itself keeps statistics about words. Mention this in your privacy information. An administrator can switch it off under Mail → External MTA API; the report addresses then disappear.

Protection against wrong reports: reports wait for 10 minutes, each user can send 50 and each server 500 per day, a mail counts only once, and a mail that two servers judge differently is not learned any more. The filter is shared by all servers of the MTA and starts to count after it has learned 200 spam and 200 wanted mails.

Mailbox quota

A default storage limit for all mailboxes can be set under Default mailbox quota (for example 5G; empty or 0 means unlimited). On each mailbox page an individual limit overrides the default. Usage is shown there as well. Incoming mail for a full mailbox is rejected by the server (552 Quota exceeded).

Client auto configuration

The DNS diagnostics page shows SRV records per mail domain. With them, apps such as Apple Mail find the server automatically. The portal also answers Thunderbird and Outlook auto configuration requests for the mail domains of this instance; the hostnames autoconfig.<domain> and autodiscover.<domain> are not served yet.

Mail queue

Administrators see undelivered messages under Mail queue including the reason for the delay, and can retry or delete them.

Distribution lists

Every group can get an email address under Distribution lists / Shared mailboxes. Mail sent to this address is delivered to all members of the group, including the members of groups nested in it. Members need a mailbox or an email address themselves. Groups of the type Distribution group are meant for this purpose and carry no permissions; Security groups can also be used as a list.

Shared mailboxes

On the page Distribution lists / Shared mailboxes a group can be used as a shared mailbox instead of a distribution list. Mail to its address lands in one mailbox. All members of the group, including members of nested groups, can read and edit it. In the mail program (for example SnappyMail) it appears as the folder shared/<address>. Users can log in with their email address or their short user name; both open the same mailbox. Users whose email address belongs to an external domain cannot log in to the mail server. Changes to the membership take effect within a few minutes at the latest. The storage limit of the mailbox is set on the same page.

Delivery errors of lists

If a mail to a distribution list cannot be delivered to one member, the error message does not go to the sender (who reached the other members) but to a contact address. Set it on the page Distribution lists / Shared mailboxes; by default it is the address of the Administrator. Changes to list memberships take effect immediately or within a few minutes.

Sender check and sending with group addresses

Authenticated users can only send with their own addresses. On the page Distribution lists / Shared mailboxes the option Members may send with this address allows all members of a group (including nested groups) to use its main address as sender. With a central MTA the address is registered there as allowed sender and counts towards the sender limit of the instance. Members get an identity with this address in SnappyMail automatically (after their first login, within a minute); mail sent with it from a shared mailbox is stored in the shared Sent folder. In other mail programs they add the identity themselves. Distribution lists only deliver to members whose address belongs to a mail domain of this server; external senders can still write to the list.

Health check

On the server bash /usr/lib/libre-workspace/modules/mail/lib/selftest.sh checks the services, ports, configuration and the last sync run of the mail module and prints OK or FAIL for each check.

System mail and the sender noreply

Every instance with the mail module has the sender noreply@<domain>. It does not count against the limit of allowed sender addresses. Mails of the server itself (for example from root, Caddy, cron or Fail2ban) are sent with this sender. Mails to root, postmaster or abuse are forwarded to the email address of the Administrator and to the additional email addresses for system emails of the portal. If Disable all monitoring mails is set they are discarded.

As long as no own SMTP server is configured under System configuration -> Email, the portal and its modules (for example Nextcloud) send through the mail module with noreply@<domain>. Own settings are never overwritten.

Without the mail module and without own settings the portal uses noreply@<domain> as sender of its system mails as well.