iRedMail
The iRedMail connector reads a server in two ways. Mail and Sieve scripts come over IMAP and ManageSieve, signed in through a Dovecot master user. Domains, accounts, password hashes, display names, quotas, aliases and forwardings come from the vmail database, which Vandelay queries with the mysql or psql client on the server through host access. Calendars and address books come from SOGo over CalDAV and CardDAV, when a SOGo superuser is configured. The MariaDB and PostgreSQL backends are supported. iRedMail with an OpenLDAP backend has no connector; it is migrated as an other IMAP server, with its accounts listed in a CSV file.
iRedMail runs Dovecot and Postfix on a server 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.
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. iRedMail has no files or sender identities for Vandelay to read.
Vandelay follows the same rules as iRedMail’s own Postfix and Dovecot queries:
- An active domain is migrated with its alias domains and its catch-all address.
- A mailbox keeps its password hash, its display name and its quota, which iRedMail stores in MB. A hash is carried when Stalwart supports its scheme, as described in Password hashes.
- A mailbox that is disabled, or that belongs to a disabled domain, is created disabled on Stalwart.
- A per-account alias becomes an alias of that account, and a mail alias with several members becomes a mailing list.
The queries are SELECT statements on the tables domain, alias_domain, mailbox, used_quota, forwardings, maillists, alias, moderators, share_folder, anyone_shares, sender_bcc_user, sender_bcc_domain, recipient_bcc_user, recipient_bcc_domain and sender_relayhost. They write nothing. Each table may return at most 500,000 rows and each query at most 64 MiB of output; a larger server fails discovery with an error instead of being read in part.
DKIM keys are not read. In a server-scope project with “DKIM keys” left on import, Stalwart generates a new key for each domain, whose DNS record must be published before mail is sent from Stalwart.
Source preparation
Section titled “Source preparation”-
Create a master user. iRedMail’s Dovecot already reads master users from
/etc/dovecot/dovecot-master-userswith the separator*, but after installation the file holds at most SOGo’s ownsogo_sieve_masteruser. Generate a hash, append a line to the file and reload Dovecot:Terminal window doveadm pw -s SSHA512systemctl reload dovecot -
To carry Sieve filters, make ManageSieve reachable. iRedMail binds it to
127.0.0.1:4190, so either Vandelay runs on the mail server, or theaddresssetting of theinet_listener sieveblock in/etc/dovecot/dovecot.confis changed, Dovecot reloaded, and port 4190 allowed from the Vandelay host in the firewall. Without ManageSieve, no filter is migrated. -
Give Vandelay host access to the server as root, locally or over SSH. The database clients sign in with root’s own credentials, so no database password ever appears in the plan or on a command line:
-
MariaDB: the client reads
/root/.my.cnf, which the iRedMail installer writes. -
PostgreSQL: root has no PostgreSQL role, so copy the password line of the read-only
vmailrole from thepostgresuser’s.pgpassto root’s. On Debian and Ubuntu:Terminal window grep ':vmail:' /var/lib/postgresql/.pgpass > /root/.pgpasschmod 600 /root/.pgpassOn Red Hat and its clones, the source file is
/var/lib/pgsql/.pgpass.
-
-
Turn on IMAP, and Sieve where it is wanted, for every mailbox that should be copied. Dovecot refuses a mailbox whose IMAP access is off even to the master user. The columns are
enableimapsecuredandenablesievesecuredover TLS, andenableimapandenablesievewhen Vandelay connects without TLS. Enable the disabled mailboxes whose mail should be copied, too. -
To carry SOGo calendars and address books, choose an existing mailbox to read them, for instance
[email protected], and make it a SOGo superuser: in/etc/sogo/sogo.conf, replace the commented//SOGoSuperUsernames = ();line with the following, then restart SOGo withsystemctl restart sogo:SOGoSuperUsernames = ("[email protected]");The superuser reads every mailbox of every domain and has full rights on all of them, so the line is put back, and SOGo restarted, when the migration is done.
The same steps are printed by vandelay migrate guide iredmail and shown on the Source: access step of the web UI and the TUI.
SOGo creates the personal calendar, the personal address book and a profile row in its sogo database the first time any user opens a mailbox that has never used SOGo, even when the request only reads. Vandelay’s reads therefore leave these rows on the source, and for an active mailbox that SOGo does not resolve, it creates the same rows for its anonymous user. Where this matters, back up the sogo database first.
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 and apply to iRedMail: Dovecot trusts the proxy’s address in /etc/dovecot/dovecot.conf, Postfix lets it send XCLIENT, and Postfix accepts mail relayed from Stalwart without checking it again. iRedMail adds two places where Stalwart’s address must be trusted as well:
-
iRedAPD. iRedMail’s policy service runs before
permit_mynetworksinsmtpd_recipient_restrictions, so adding Stalwart to Postfix’smynetworksalone does not exempt it from greylisting and the other iRedAPD checks. iRedMail’s ownmain.cfasks for every address added tomynetworksto be listed in iRedAPD’sMYNETWORKStoo, in/opt/iredapd/settings.py, which iRedAPD upgrades keep. iRedAPD is restarted afterwards:MYNETWORKS = ["203.0.113.20"] -
Amavisd. Amavisd treats the networks in its
@mynetworksas internal, so Stalwart’s address is appended there. Its configuration is/etc/amavis/conf.d/50-useron Debian and Ubuntu and/etc/amavisd/amavisd.confon Red Hat and its clones.
Plan settings
Section titled “Plan settings”The endpoints are “IMAP URL” (source.imap, --imap-url), the IMAPS address of the server on port 993, and “ManageSieve URL” (source.sieve, --sieve-url). The master user is required: “Master user” (source.master.name, --master-user), for example [email protected], and “Master, admin or service account password” (source.master.password, --master-password), a secret reference. The separator * is the default “Master login format”, as described in Master user.
Host access is required, and the database is set by two fields:
- “Database server” (
source.sql.engine,--sql-engine):mysqlfor MariaDB or MySQL, orpostgres. - “Database” (
source.sql.database,--sql-database): for MariaDB, the database name,vmailin a standard installation; for PostgreSQL, a connection string for thevmailrole, such asdbname=vmail user=vmail host=127.0.0.1. Only the keysdbname,user,host,port,sslmodeandconnect_timeoutare accepted, without quotes; a password is refused, because it belongs in~/.pgpass.
SOGo has no field on the Source: access step. It is set in plan.toml as a [source.sogo] table with the server’s web address (url, to which Vandelay appends /SOGo), 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”. The URL must use HTTPS, except on a loopback address, and when the source’s certificate is pinned, the same host name as the IMAP URL, because the pin applies to that host only. The SOGo address is part of the source’s identity: it is added before the first work is admitted, because adding, removing or changing it afterwards is refused like any other change of source. When the plan migrates neither calendars nor contacts, Vandelay never contacts SOGo.
The following excerpt reads a MariaDB-based server over SSH, with SOGo:
[source]system = "iredmail"imap = "imaps://mail.example.org"sieve = "sieve://mail.example.org:4190"cleartext = "forbid"
[source.master]password = "env:IREDMAIL_MASTER_PASSWORD"form = "*"
[source.host]kind = "ssh"
[source.sql]engine = "mysql"database = "vmail"
[source.sogo]url = "https://mail.example.org"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=iredmail \ --imap-url=imaps://mail.example.org \ --sieve-url=sieve://mail.example.org:4190 \ --master-password=env:IREDMAIL_MASTER_PASSWORD \ --host-access=ssh \ --sql-engine=mysql \ --sql-database=vmailItems not migrated
Section titled “Items not migrated”Pre-flight lists the following as losses, each naming the table and row where it applies:
- Forwarding of a mailbox to other addresses, reported as
Postfix virtual_alias_maps forwarding is not migrated; recreate it as a redirect rule: <targets>, with whether the source also kept a local copy. - mlmmj mailing lists, with their subscribers, archives and settings:
an mlmmj mailing list in iRedMail; its subscribers, archive and settings are not migrated; recreate it on the target. - Automatic BCC (
sender_bcc_*,recipient_bcc_*) and per-sender relay hosts (sender_relayhost). - Backup MX domains, and the aliases, forwardings and catch-all of a disabled domain.
- Domains delivered elsewhere. A domain whose
transportis anything other than local delivery, such assmtp:[10.0.0.5]:25, is not created as a local domain, and neither are its mailboxes, aliases, forwardings and catch-all; that routing is set up on Stalwart. - Turned-off services. The mail of a mailbox with IMAP turned off is not read, nor the filters of a mailbox with Sieve turned off (
Sieve is turned off for this mailbox in iRedMail ... its filters are not read, so recreate them on the target or turn it on for the migration). - Per-mailbox restrictions of enabled mailboxes: a mailbox’s own
transport(the mailbox is migrated, and Stalwart delivers its mail locally), the allowed networks (allow_nets), turned-off sending (enablesmtpsecured) and turned-off delivery (enabledeliver). Stalwart applies none of them. A disabled mailbox records none of these losses. - Alias policies. The sender restrictions of a mail alias (
accesspolicyother than public) and its moderators, which iRedAPD enforces, are not migrated, so Stalwart accepts mail for those addresses from anyone. - Mailboxes Dovecot does not sign in. A mailbox in a backup MX domain, in a domain whose mail iRedMail relays elsewhere, or in a domain that is not in
vmail.domainis not migrated, for example<address>: its domain "<domain>" is not in vmail.domain, so Dovecot does not sign it in; not migrated. A mailbox listed again in another letter case is migrated once:vmail.mailbox:<row>: <address> is listed again in another letter case; Dovecot signs in only one of them; not migrated. - Alias domains that are also domains. An
alias_domainrow whose alias is itself a domain invmail.domainis never migrated as an alias of another domain:the alias domain "<alias>" is itself a domain in vmail.domain; it may still work on the source, but is refused so that no row takes over another domain; not migrated as an alias domain. That domain is handled only as its ownvmail.domainrow says. - Shared IMAP folders (
share_folder,anyone_shares), reported as<owner>: shares IMAP folders with <member>; folder sharing is not migrated, so share them again on the target. - Refused spellings. A domain, alias domain, mailbox, forwarding address or catch-all with a final dot, with upper-case letters outside ASCII, or on PostgreSQL with any upper case, is refused, as is an address whose domain is neither the row’s domain nor one of its alias domains, so that no row takes over another domain’s address. Some of these may still work on the source; the loss names the table, row and value, and the row is corrected on the source or the address created on Stalwart.
- Disabled mailboxes. Dovecot refuses a disabled mailbox even to the master user, so a run copies none of its mail and records a loss; what an earlier run copied stays. Enabling the mailbox in iRedAdmin and running again copies the rest.
- SOGo data. Without
[source.sogo], no calendar or address book is copied: each account recordsSOGo 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. A folder that a mailbox subscribed to, or that another user shared with it, belongs to its owner and is reported instead of migrated under the subscriber. A disabled mailbox is not read, because SOGo does not resolve it.
The following are neither migrated nor reported: the global Sieve filter that runs before every user’s filters (/var/vmail/sieve/dovecot.sieve), the DKIM keys, and the other per-account settings of iRedAdmin, such as the remaining per-service flags, domain administrators and account expiry.
Troubleshooting
Section titled “Troubleshooting”SOGo refuses the superuser
Section titled “SOGo refuses the superuser”Pre-flight signs in to SOGo once as the superuser and stops with SOGo refused the sign-in of the superuser <user> (<reason>); it is not retried, because SOGo locks a mailbox out after repeated failures; check its password and SOGoSuperUsernames, or remove sogo from the plan. During a run, each job signs in at most once, and after a refusal the rest of its accounts record SOGo refused the superuser <user> (<error>); no further SOGo sign-in is tried in this run. Check the password reference and the SOGoSuperUsernames line, restart SOGo, and run again. <user> is not listed in SOGoSuperUsernames means that SOGo accepted the password but did not give the mailbox superuser rights.
PostgreSQL connection string refused
Section titled “PostgreSQL connection string refused”the PostgreSQL database must be a plain name or key=value pairs of dbname, user, host, port, sslmode and connect_timeout, without quotes or backslashes; put the password in ~/.pgpass means that the connection string holds a password or another key. Remove it and put the password into root’s ~/.pgpass, as described in Source preparation.
Mailbox not read because IMAP is off
Section titled “Mailbox not read because IMAP is off”<address>: IMAP is turned off for this mailbox in iRedMail (enableimapsecured is 0) and Dovecot refuses it even to the master user; turn it on for the migration or its mail is not read names the column to set to 1 for the migration.