Skip to content

mailcow

The mailcow connector reads a server in up to four ways. The domains, mailboxes, aliases, resources, mailbox groups and DKIM keys come from the mailcow API. Mail and Sieve scripts come over IMAP and ManageSieve, signed in through mailcow’s Dovecot master user. Password hashes, and the DKIM keys that the API hides, come from mailcow’s own containers through host access. Calendars and address books come from SOGo over CalDAV and CardDAV. Only the API key and the master user are required; the others add data.

mailcow runs Dovecot and Postfix in containers on a host the operator controls, so both cutover strategies apply: a zero-downtime migration with the Stalwart proxy in front of the server, or a one-shot migration per domain. Detection recognises mailcow from its API description.

Mail is copied over IMAP with the folder tree, and Sieve scripts over ManageSieve when its URL is set. Vacation replies and filters exist only as Sieve scripts. With a SOGo superuser, each active mailbox’s calendars and address books are read from SOGo. mailcow has no files or sender identities for Vandelay to read.

Vandelay reads the API with GET requests only, and writes nothing on the source:

  • An active domain is migrated with its alias domains and its catch-all address.
  • A mailbox keeps its display name and quota, and its password hash when host access is set. A hash is carried when Stalwart supports its scheme, as described in Password hashes. A mailbox that authenticates elsewhere, or that mailcow forces to change its password, gets a temporary password instead. A shared mailbox is provisioned as a Stalwart group, whose members can send from its address.
  • An alias with one mailbox as its target becomes an alias of that account, and an alias with several targets becomes a mailing list.
  • A resource becomes a Stalwart resource, a room or equipment, and a mailbox group becomes a group with its members.
  • The DKIM key of each domain is carried when “DKIM keys” imports it, which only a server-scope project does. The API returns the private key only when SHOW_DKIM_PRIV_KEYS is on in mailcow’s configuration; otherwise Vandelay reads it from the redis-mailcow container through host access.
  1. Create an API key. In the mailcow admin interface, open the API settings, enable the read-only API, and add the address of the Vandelay host to its allow list; mailcow refuses a key from any other address. The read-only key is enough, because Vandelay only sends read requests.

  2. Set up mailcow’s master user, which signs in to every mailbox without the users’ passwords. In mailcow.conf, set DOVECOT_MASTER_USER and DOVECOT_MASTER_PASS, then run docker compose up -d so that Dovecot reads them. mailcow appends @mailcow.local to the name, so a DOVECOT_MASTER_USER of vandelay signs in as [email protected].

  3. To carry the users’ passwords, give Vandelay host access to the mailcow host, locally as root (/) or over SSH. Vandelay runs docker ps and docker exec there to read the password hashes from the mysql-mailcow container, and the hidden DKIM keys from redis-mailcow. The account Vandelay signs in as must be allowed to run docker, which on most hosts means root or the docker group; both can control every container, so that account is used for the migration only. Without host access, every account gets a temporary password, and a DKIM key that the API hides is not carried.

  4. To carry calendars and address books, choose an existing mailbox to read them, for instance [email protected], and make it a SOGo superuser: in data/conf/sogo/sogo.conf, set the following, and restart SOGo with docker compose restart sogo-mailcow:

    SOGoSuperUsernames = ("[email protected]");

    The superuser can read and change every mailbox’s calendars and contacts, so the line is removed, and SOGo restarted, when the migration is done.

  5. Activate the mailboxes whose mail should be copied. mailcow refuses every login to an inactive mailbox, the master user’s included, so an inactive mailbox is set active, or to “login disallowed”, for the migration.

The same steps are printed by vandelay migrate guide mailcow and shown on the Source: access step of the web UI and the TUI.

The settings that a Dovecot and Postfix source needs behind the Stalwart proxy are described in Proxy mode settings. On mailcow they differ in the following ways:

  • Where settings go. mailcow generates its configuration, so a change in a generated file is lost. Additional Dovecot settings, such as login_trusted_networks, go into data/conf/dovecot/extra.conf, which is created if missing, and take effect with docker compose restart dovecot-mailcow. Postfix settings go into data/conf/postfix/extra.cf, which overrides the generated main.cf, and take effect with docker compose restart postfix-mailcow.
  • mynetworks. mailcow does not set mynetworks; Postfix derives the trusted networks from mynetworks_style = subnet. A value set in extra.cf replaces that derivation, so it lists mailcow’s own networks as well: the loopback addresses and the IPV4_NETWORK and IPV6_NETWORK ranges from mailcow.conf, followed by Stalwart’s address.
  • rspamd. rspamd rejects mail relayed from Stalwart unless Stalwart’s address is a forwarding host. The address is added in the mailcow UI, or with POST /api/v1/add/fwdhost and filter_spam set to 0, which makes rspamd accept the mail without scoring it.
  • Mail for switched accounts. mailcow generates its own transport configuration, so transport entries for switched accounts are not added; Vandelay’s catch-up passes copy that mail instead.

mailcow’s web server serves the mailcow administration interface under /admin and SOGo under /SOGo on the same name as IMAP. When the proxy routes HTTP by account, a switched account’s requests go to Stalwart whatever their path, so CalDAV and CardDAV clients configured with a SOGo URL, such as /SOGo/dav/[email protected]/Calendar/personal/, no longer reach their collections after the switch, because Stalwart does not serve SOGo’s paths, and are reconfigured with Stalwart’s addresses. A route that pins /admin to Stalwart for its WebUI makes the mailcow administration interface unreachable through the proxy; it is then opened at the source’s internal address.

The API is reached at “Admin URL” (source.url, --admin-url), the HTTPS web address of the mailcow server, with “API key” (source.api_key, --api-key) as a secret reference. The API must be reached over HTTPS, except on a loopback address.

The master user is “Master user” (source.master.name, --master-user), the full name such as [email protected], and “Master, admin or service account password” (source.master.password, --master-password). The Source: access step asks for “IMAP URL” (source.imap, --imap-url), usually imaps:// and the server’s name; a plan file that leaves it out makes Vandelay use port 993 of the admin URL’s host. “ManageSieve URL” (source.sieve, --sieve-url) carries the Sieve filters.

Host access is optional, as described above. SOGo has no field on the Source: access step: it is set in plan.toml as a [source.sogo] table with the superuser’s address (user) and a secret reference to that mailbox’s own password (password). On the host, add the table to plan.toml in the project directory and apply it with vandelay migrate plan reload. In the web UI, open Plan, choose “Download plan.toml”, add the table with password = "ask" and upload the file again with “Upload plan.toml”. Add it before the first copy. Vandelay reaches SOGo at the admin URL. Pre-flight signs in once as the superuser and stops when SOGo refuses it; when the plan migrates neither calendars nor contacts, SOGo is never contacted.

The following excerpt reads a mailcow server with host access over SSH and SOGo:

[source]
system = "mailcow"
url = "https://mail.example.org/"
api_key = "env:MAILCOW_API_KEY"
imap = "imaps://mail.example.org"
sieve = "sieve://mail.example.org:4190"
cleartext = "forbid"
[source.master]
password = "env:MAILCOW_MASTER_PASSWORD"
form = "*"
[source.host]
kind = "ssh"
destination = "[email protected]"
[source.sogo]
password = "env:SOGO_PASSWORD"

The following command sets the same source without the SOGo table, which is added to plan.toml afterwards:

Terminal window
vandelay migrate source \
--system=mailcow \
--admin-url=https://mail.example.org \
--api-key=env:MAILCOW_API_KEY \
--imap-url=imaps://mail.example.org \
--sieve-url=sieve://mail.example.org:4190 \
--master-password=env:MAILCOW_MASTER_PASSWORD \
--host-access=ssh \

Pre-flight lists the following as losses:

  • Forwarding, reported as mailcow mailbox forwarding is not migrated; recreate it as a redirect rule: <targets>, with whether the source also kept a local copy.
  • Inactive mailboxes. mailcow mailbox <address> is inactive: mailcow refuses every login to it, the master user included, so its mail and Sieve scripts are not copied while it is inactive; enable it, or set it to login disallowed (active 2), and run again to copy them. Their calendars and contacts are not read either, because SOGo does not resolve an inactive mailbox.
  • Unusable login names. The mail and Sieve scripts of a mailbox whose address holds a character mailcow’s Dovecot refuses in a login name; only ASCII letters, digits, ., -, _ and @ are accepted.
  • BCC maps and recipient maps.
  • Sender permissions of mailboxes and mailbox groups, and the IMAP and SOGo folder sharing that mailbox groups grant.
  • Inactive objects. The aliases, mailing lists, groups, resources and catch-all of an inactive domain (its mailboxes are migrated disabled), backup MX relay domains, and inactive alias domains, aliases, resources and groups.
  • Catch-alls with several targets, because Stalwart takes one: mailcow catch-all @<domain> has <n> targets; Stalwart takes one; not migrated.
  • Hidden or missing DKIM keys. A key that the API hides when no host access is set, and a key that mailcow’s Redis no longer holds; the latter is set up again in mailcow’s DKIM settings before discovering again. A key that is not valid base64 (the mailcow API returns a private key that is not valid base64) or not a usable PEM key (mailcow holds a private key for it that is not a usable PEM key) is not carried either. Without a carried key, a server-scope project has Stalwart generate a new one, whose DNS record must be published; an account-scope project carries no DKIM keys at all.
  • Special alias targets. mailcow’s special targets null@localhost, spam@localhost and ham@localhost have no counterpart: an alias that delivers only to them is not migrated (mailcow alias <address> delivers only to <targets>; not migrated), and an alias that also has other targets is migrated without them.
  • Resource details. A resource of a kind Stalwart does not have is migrated as equipment, and a resource that accepts a limited number of overlapping bookings is migrated as accepting conflicts; each is reported.
  • SOGo data when the plan names no SOGo superuser (each account records SOGo calendars and contacts of <address> are not migrated: the plan names no SOGo superuser (an existing mailbox listed in SOGoSuperUsernames), and pre-flight names that loss for its sample accounts), and folders that a mailbox subscribed to or that another user shared with it, which belong to their owner.
  • Invalid or duplicate objects. Domains, mailboxes and aliases with an invalid name, in a domain that is not migrated, or with an address already taken by an object listed before them; the loss names the object and its value.

the mailcow API key is empty; mailcow answers an empty key with an empty listing means that the key reference resolved to an empty value. When the key is set but mailcow refuses it, either the key is unknown or inactive, or the Vandelay host’s address is missing from the key’s allow list. <field>: the API must be reached over https (http only on a loopback address) means that the admin URL uses http:// on a routable address.

expected one running mysql-mailcow container on the source host, found <n> means that docker ps on the host found no running database container, or several. A failed host read is reported with reading the mailcow password hashes through host access failed; fix host access (docker on the source host), or remove source.host from the plan to migrate without hashes (accounts get temporary passwords) and without the Redis DKIM fallback.