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.
Migrated data
Section titled “Migrated data”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_KEYSis on in mailcow’s configuration; otherwise Vandelay reads it from theredis-mailcowcontainer through host access.
Source preparation
Section titled “Source preparation”-
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.
-
Set up mailcow’s master user, which signs in to every mailbox without the users’ passwords. In
mailcow.conf, setDOVECOT_MASTER_USERandDOVECOT_MASTER_PASS, then rundocker compose up -dso that Dovecot reads them. mailcow appends@mailcow.localto the name, so aDOVECOT_MASTER_USERofvandelaysigns in as[email protected]. -
To carry the users’ passwords, give Vandelay host access to the mailcow host, locally as root (
/) or over SSH. Vandelay runsdocker psanddocker execthere to read the password hashes from themysql-mailcowcontainer, and the hidden DKIM keys fromredis-mailcow. The account Vandelay signs in as must be allowed to rundocker, which on most hosts means root or thedockergroup; 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. -
To carry calendars and address books, choose an existing mailbox to read them, for instance
[email protected], and make it a SOGo superuser: indata/conf/sogo/sogo.conf, set the following, and restart SOGo withdocker 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.
-
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.
Proxy mode settings
Section titled “Proxy mode settings”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 intodata/conf/dovecot/extra.conf, which is created if missing, and take effect withdocker compose restart dovecot-mailcow. Postfix settings go intodata/conf/postfix/extra.cf, which overrides the generatedmain.cf, and take effect withdocker compose restart postfix-mailcow. - mynetworks. mailcow does not set
mynetworks; Postfix derives the trusted networks frommynetworks_style = subnet. A value set inextra.cfreplaces that derivation, so it lists mailcow’s own networks as well: the loopback addresses and theIPV4_NETWORKandIPV6_NETWORKranges frommailcow.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/fwdhostandfilter_spamset to0, 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.
Plan settings
Section titled “Plan settings”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"
[source.sogo]password = "env:SOGO_PASSWORD"The following command sets the same source without the SOGo table, which is added to plan.toml afterwards:
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 \Items not migrated
Section titled “Items not migrated”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@localhostandham@localhosthave 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.
Troubleshooting
Section titled “Troubleshooting”API key refused or empty listing
Section titled “API key refused or empty listing”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.
Password hashes not read
Section titled “Password hashes not read”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.