Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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 'username@olddomain.com' need to arrive at 'username@newdomain.com', users need to be able to log in (Postfixadmin/Dovecot) with 'username@olddomain.com' and 'username@newdomain.com', 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


password = ****
hosts = localhost
dbname = pf_adm
query = SELECT CONCAT(maildir, 'Maildir/') AS maildir FROM mailbox WHERE username='%s' AND active = '1'


user = ****
password = ****
hosts = localhost
dbname = pf_adm
query = SELECT domain FROM domain WHERE domain='%s' AND backupmx = '0' AND active = '1'


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 = postmaster@olddomain.com
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 | +------------------------+-------------------------+------------+---------------+ | username@olddomain.com | olddomain.com/username/ | username | olddomain.com | +------------------------+-------------------------+------------+---------------+
share|improve this question
I don't know if postfix will explode if you do this, but wouldn't having both the olddomain and newdomain accounts point to the same maildir have the same mail available in both accounts? –  DerfK Nov 13 '12 at 13:21
@DerfK I guess I could make a symlink from ${mail_spool_directory}/olddomain.com to ${mail_spool_directory}/newdomain.com but this would only make the mail available if I duplicate each account with '@newdomain.com' instead of '@olddomain.com'. I rather not recreate each account. –  siebz0r Nov 13 '12 at 13:29
add comment

1 Answer

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
share|improve this answer
So how should a query for a user look? I'm guessing SELECT CONCAT(maildir, 'Maildir/') AS maildir FROM mailbox WHERE local_part='%s' AND active = '1' but this won't work when a user logs in with an email address, right? I also don't get what you mean with 'using the same query'. –  siebz0r Nov 13 '12 at 13:13
I have no idea what "log in" means to you; postfix does not log users in. –  adaptr Nov 13 '12 at 13:36
I should have noted I am using Postfixadmin and Dovecot too. –  siebz0r Nov 13 '12 at 14:05
Those are unrelated to the postfix MTA. If you need help with them, provide adequate information: the full output of postconf -n, doveconf -n, and relevant log messages that show what is going wrong. –  adaptr Nov 13 '12 at 14:06
I have modified the question accordingly, if more info is needed I am happy to supply it. –  siebz0r Nov 13 '12 at 14:15
add comment

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.