Postfix/Dovecot support multiple domains
I have a server running Postfix/Dovecot with a MySQL back-end which is configured to use the domain name 'olddomain.com'. I am migrating everything to use another domain 'newdomain.com' and Postfix/Dovecot/Postfixadmin all need to be migrated too. However I need to support both domain names for a while and this should be transparent for users. Emails that are send to '[email protected]' need to arrive at '[email protected]', users need to be able to log in (Postfixadmin/Dovecot) with '[email protected]' and '[email protected]', etc.
I cannot figure out how to do this to support the named use cases, so any help would be appreciated.
Relevant config stuff:
postconf -n
command_directory = /usr/sbin config_directory = /etc/postfix daemon_directory = /usr/libexec/postfix data_directory = /var/lib/postfix debug_peer_level = 2 debugger_command = PATH=/bin:/usr/bin:/usr/local/bin:/usr/X11R6/bin ddd $daemon_directory/$process_name $process_id & sleep 5 dovecot_destination_recipient_limit = 1 html_directory = no mail_owner = postfix mail_spool_directory = /var/spool/mail mailq_path = /usr/bin/mailq manpage_directory = /usr/share/man mynetworks_style = host newaliases_path = /usr/bin/newaliases queue_directory = /var/spool/postfix readme_directory = no relay_domains = mysql:/etc/postfix/mysql_relay_domain_maps.cf relayhost = ******* sample_directory = /etc/postfix sendmail_path = /usr/sbin/sendmail setgid_group = postdrop smtpd_recipient_restrictions = permit_sasl_authenticated, permit_mynetworks, reject_unauth_destination smtpd_sasl_auth_enable = yes smtpd_sasl_path = private/auth smtpd_sasl_type = dovecot unknown_local_recipient_reject_code = 550 virtual_alias_maps = mysql:/etc/postfix/sql_virtual_alias_maps.cf virtual_mailbox_domains = mysql:/etc/postfix/sql_virtual_domain_maps.cf virtual_mailbox_maps = mysql:/etc/postfix/sql_virtual_mailbox_maps.cf virtual_transport = dovecot
sql_virtual_mailbox_maps.cf:
password = **** hosts = localhost dbname = pf_adm query = SELECT CONCAT(maildir, 'Maildir/') AS maildir FROM mailbox WHERE username='%s' AND active = '1'
sql_virtual_domain_maps.cf:
user = **** password = **** hosts = localhost dbname = pf_adm query = SELECT domain FROM domain WHERE domain='%s' AND backupmx = '0' AND active = '1'
sql_virtual_alias_maps.cf:
user = **** password = **** hosts = localhost dbname = pf_adm query = SELECT goto FROM alias WHERE address='%s' AND active = '1'
doveconf -n
# 2.1.9: /etc/dovecot/dovecot.conf # OS: Linux 3.4.5-hardened i686 Gentoo Base System release 2.1 ext4 auth_verbose = yes first_valid_gid = 12 first_valid_uid = 8 last_valid_gid = 12 last_valid_uid = 8 mail_gid = 12 mail_location = maildir:/var/mail/%d/%n/Maildir/:INDEX=/var/mail/%d/%n/indexes mail_uid = 8 namespace inbox { inbox = yes location = mailbox Drafts { special_use = \Drafts } mailbox Junk { special_use = \Junk } mailbox Sent { special_use = \Sent } mailbox "Sent Messages" { special_use = \Sent } mailbox Trash { special_use = \Trash } prefix = } passdb { args = /etc/dovecot/dovecot-sql.conf.ext driver = sql } postmaster_address = [email protected] protocols = imap service auth { unix_listener /var/spool/postfix/private/auth { group = postfix mode = 0660 user = postfix } unix_listener auth-userdb { group = mail mode = 0600 user = mail } } ssl_cert =Bonus info (if needed), users are stored like this:
+------------------------+-------------------------+------------+---------------+ | username | maildir | local_part | domain | +------------------------+-------------------------+------------+---------------+ | [email protected] | olddomain.com/username/ | username | olddomain.com | +------------------------+-------------------------+------------+---------------+
Persistently requiring the full domain name for every address is biting you in the backside here.
It really isn't necessary since all you have is the one domain, so a simple solution would be to alter the SQL lookups to act on the localpart only.
Add the new domain to virtual_mailbox_domains and perform only a localpart lookup on virtual_mailbox_maps.
Both domains and all users in it will be accepted and delivered.
Using a complicated query for virtual_mailbox_domains isn't likely to help, either.
Just list the domain(s) in virtual_mailbox-domains:
virtual_mailbox_domains = olddomain, newdomain