This article explains how to migrate email accounts/mailboxes from a sendmail server to a Qmail server. A challenging task for any sysadmin implementing a Migration would be to migrate all the email accounts from one Mail server to another preserving all the settings, such as usernames and passwords.
This document helps you, only if your Qmail system is installed with VpopMail (not VmailMgr). Installing and configuring qmail+vpopmail is out of the scope of this article.(Refer to qmailrocks.org and lifewithqmail.org to install Qmail and Vpopmail) This article exclusively covers only the Migration aspects.
Here is what you have.
* Sendmail server, the list of usernames, the corresponding system passwords (encrypted, not clearpasswords) and the Mailboxes
* Qmail server with VpopMail.
Create Mailboxes in the new server.
The first step is to create all email accounts in the new server. In order to do this,
collect the usernames and encrypted passwords from the old server. There is no way you could
get the clear password from a sendmail system, so we collect the encrypted passwords.
Before adding the email accounts, let me explain to you some features of the VpopMail binaries.
Suppose you installed VpopMail in the path $VPOPMAILHOME, say /home/vpopmail, you can find all the VpopMail binaries in $VPOPMAILHOME/bin directory.
# cd $VPOPMAILHOME/bin/<br /><br />
1. vadddomain - is used to add a domain into qmail server.
2. vdeldomain - delete a domain from the qmail system.
3. vchangepw - to change the password of an email account.
4. vmoduser - to modify a user account.
5. vsetuserquota - to set the quota of an email account
6. vadduser - to add email accounts in the server.
7. vchkpw - the password verification module.
8. vdominfo - display the details of a domain, including passwords.
9. vpasswd - change password of a user account
10. vuserinfo - display the email account information, including the encrypted and clear password.
You can easily manage domains and email accounts in a Qmail server using these binaries. We are going to use the vadddomain and the vadduser binaries to add domains and email accounts.
First add the domain into the server into the Qmail system.
# ./vadddomain domain.com
Please enter password for postmaster:
enter password again:
Then add emails accounts using the following format. The “-e” option is used to pass the encrypted password to vpopmail.
#vadduser -e '$1$yt5hE5rz$NXn6X6t29ci/8CYk4S44d.' firstname.lastname@example.org
#vadduser -e '$1$6io3bpHS$ALqBpZbsrXI2YVTQDeG0S.' email@example.com
#vadduser -e '$1$6io3bpHS$ALqBpZbsrXI2YVTQDeG0S.' firstname.lastname@example.org
In order to make our job easier, the usernames and passwords that we build on the old server will be formatted as a series of commands, like the example above. For example, the file “addusers.sh” now contains a series of commands.
vadduser -e '$1$yt5hE5rz$NXn6X6t29ci/8CYk4S44d.' email@example.com
vadduser -e '$1$6io3bpHS$ALqBpZbsrXI2YVTQDeG0S.' firstname.lastname@example.org
Copy this script “addusers.sh” to the new server’s $VPOPMAILHOME/bin location and execute it.
# cd $VPOPMAILHOME/bin
# sh +x addusers.sh
Half of our job is now completed. All emails accounts for the domain “domain.com” are now added to the new server. At this point, the end users will be able to access POP3 or IMAP server on the new machine, they would be able to log into their mailboxes, but they would see an empty box, rather than seeing whatever messages were on the old server.
Sendmail uses the traditional Unix mailbox format called “mbox” (where the entire mailbox is one file, Migrating the Sendmail mailbox with the messages stored one after the other) to store the emails, While Qmail uses the “Maildir” format
to store the emails. This step actually copies the contents of the mailboxes from the sendmail machine to the qmail machine, converting the messages from sendmail’s “mbox” format to qmail’s “Maildir” format.
The tool used to convert mbox to MailDir, is called mbox2mdir or mb2md.
You can download mb2md from http://freshmeat.net/projects/mb2md/
First copy the Mailbox from the old server to the new server, then run the following command from shell.
#mb2md -s MailBoxfile -d /home/vpopmail/domains/domain.com/$username/Maildir/
( replace $username with original username)
There it is. You are done…. now relax and enjoy Mail server administration.
Qmail Administration Tools
qmail-qstat - qmail-qstat is a binary installed along with the qmail server.
This command will show you how many messages are in the queue, even while qmail-send is not runnning.
messages in queue: 3037
messages in queue but not yet preprocessed: 23
From the output, you can find how many mails are in the server, and how many mails are there yet to be processed. If there are lots of mails in the server, those are probably the frozen/bounced messages.
Qmail-qread will list all messages in the queue with to address
QmHandle - qmhandle is a great tool to manage your qmail queue. Key features are colored output and the ability to view and delete messages from the queue.
You can download this tool from http://sourceforge.net/projects/qmhandle/
* You can read the qmail queue ( the qmail-read program with qmail server does the same
but the output of qmHandle is improved over qmail-qread. #qmHandle -l
* You can print queue statistics . #qmHandle -s
* You can view a message in the queue;
#qmHandle -vN ( Where N is the message number)
* You can remove one or more messages from the queue;
#qmHandle -dN ( Where is the message number to be removed )
#qmHandle -D ( delete all messages in the queue)
#qmHandle -tX ’string’ ( delete all messages with matching headers, where string to match and X specifies:
‘f’ : Who the message is from,
‘t’ : Who the message is to; or,
’s’ : What the message’s subject is #qmHandle -M ( delete all msgs in the queue from MAILER-DAEMON@hostname)
qmail-repair is a tool to repair a damaged mail queue or building a
mail-queue from scratch. It is written in python.
Download at http://pyropus.ca/software/queue-repair/
# python queue_repair.py -r ( repair the mail queue )
# python queue_repair.py -c ( force creation of mail queue )
# python queue_repair.py -t (Testing queue, do not modify queue)
About the author:
Aneesh P. K has worked in Bobcares for over 2.3 years as System Administrator. He manages Internet servers in Linux and Windows running Cpanel, Plesk, Qmail, Apache and IIS software.