In a Qmail/Vpopmail email server system, there is no direct way to rename a domain. Let’s say, you have a costumer that is using domain.net and then registers domain.com to replace domain.net. The obvious solution is to make domain.com an alias domain of domain.net, it’s just one simple command:
vaddaliasdomain domain.net domain.com
But if the old domain is to be dropped completely there is no logical reason to go for the domain alias route, except that is the quick and dirty solution. Also, it’s a bit stupid and confusing to be consuming all the email services (POP, IMAP, SMTP, Webmail, Control Panel) with credentials of the old domain when the domain in use is the new domain. All this hassle just because Vpopmail doesn’t provide a command do rename a domain.
Even with no direct command, it’s possible to rename a domain, keeping all the mailboxes (email@example.com changes to firstname.lastname@example.org), passwords, forwards, email alias, webmail preferences and contacts etc. It’s a bit painful, but doable:
- move vpomail/domains/old_domain to vpomail/domains/new_domain
- adjust if needed vpomail/domains/new_domain/.qmail-default
- adjust if needed each mailbox .qmail file in vpomail/domains/new_domain/users(1,2,3)/.qmail
- rename domain in rcpthosts or morercpthosts (if in morercpthosts run qmail-newmrh)
- rename domain in qmail/users/assign and run qmail-newu
- log in to mysql and in the vpopmail database rename the old domain table to new domain table (domain dots get converted to underscores)
- in the new renamed table update the pw_dir field to match the new domain
- update dir_control table to the new domain
- update limits table
- update valias (domain and valias_line field)
- in the roundcube database update the users and identities tables to match the new domain in the respective old domain entries
- restart qmail and test
If you have read all the way trough here, and are thinking in doing this procedure, WAIT i have a special treat, a script that takes care of all. It’s a PHP script, that should be executed in command line by root and accepts 2 arguments, the old domain and new domain. Just adjust the PHP path, the configurations (paths to stuff in the system), mark as executable and you are ready to go.
Beware, you will be running this as root, and i assure that it works fine on my server but i can’t assure that it won’t destroy yours. If you accept this terms please proceed and grab the script.