Sunday, July 5, 2009

Migrate Qmail, Vpopmail & SquirrelMail to New Server

Needed to migrate a Qmail, Vpopmail and SquirrelMail from an old machine to a brand new server with Raid 5 capabilities. Everything with the old setup was working as a charm so i wanted to keep my smartness on the hold to not to screw up anything.

Below mentioned is the procedure to effortlessly do the migration.

Setup Raid 5.

Install CentOS 5.2(RAID & LVM).

Install all the needed requirements for the mail server.

Install all the components of the mail server(Qmail, Vpopmail, SquirrelMail, etc).

Login to the old server.

#cd /home/vpopmail/domains

#vi list_vpopmail_users.sh

#!/bin/bash

for domain in *;
do for user in `ls $domain`;
do echo -n "~vpopmail/bin/vadduser" $user@$domain;
~vpopmail/bin/vuserinfo $user@$domain | grep -v "name:\|^passwd:" | sed -e 's/clear passwd://'; done; done | grep -v "no such"| grep @ |sort

#chmod 755 list_vpopmail_users.sh

#./list_vpopmail_users.sh > vpopmail_users

Open vpopmail_users and edit unwanted entries.

Move the vpopmail_users file to the new server.

Login to your new server.

#/home/vpopmail/bin/vadddomain your_domain_name your_postmaster_password

Execute the vpopmail_users file in the new server.

#./vpopmail_users

Now login to you old server.

#cd /root

#ssh-keygen -t dsa -b 1024 -f root_dsa -C 'Root dsa key'

#mv root_dsa /root/.ssh/

#scp root_dsa.pub root@new_server_ip:~

Login to your new server.

#cat root_dsa.pub >> /root/.ssh/authorized_keys

#chmod 600 /root/.ssh/authorized_keys

#rm -rf root_dsa.pub

Login to your old server and issue the following command.

#rsync -avuzr --stats --delete -e "ssh -i /root/.ssh/root_dsa" /home/vpopmail/domains/your_domain_name root@new_server_ip:/home/vpopmail/domains/

Copy SquirrelMail from old to new server.

Login to your new server.

#scp -r root@old_server_ip:/var/www/html/webmail /var/www/html/

I had my SquirrelMail data and attachments in the /var/wmdata and /var/wmattachments. So copy your data and attachments directory from old server to the new one using the scp command.

Next we need to change permissions of the data and attachments directory to enable apache to have write access. Look up apache config to find the username and group under which it runs and change the permissions accordingly.

#chown -R apache:apache /var/your_data_directory

#chown -R apache:apache /var/your_attachment_directory

Next change the ip address used by SquirrelMail by running conf.pl.

#cd /var/www/html/webmail/config

#./conf.pl

And that's it folks!!!.

The solution is nothing new and i have posted what just worked for me. I owe google...

Sniff outgoing and incoming mails in Qmail

The client had a email policy and requested mail sniffing feature to be implemented in Qmail. My personal moral standpoint doesn't matter here and explained below is just the technology feasibility for sniffing all outgoing and incoming mails in a Qmail server.

It's quite easy to sniff mails using "QUEUE_EXTRA" and "QUEUE_EXTRALEN" as explained elsewhere on the Internet. This solution will help to setup an sniff account to view all outgoing and incoming mails. But this solution is not smart enough, so it will even copy all the marked mails. The sniff account will become clogged with many similar mails. The best solution would be to club the above sniff method with "eliminate-dups". This method will ensure that your sniff account will have a single unique copy of marked mail.

Sniff Method:

Open Qmail source file extra.h and modify QUEUE_EXTRA and QUEUE_EXTRALEN as mentioned below.

QUEUE_EXTRA here has sniff@domainname.com. Please replace that with your sniff acount name and your domain name.

QUEUE_EXTRALEN 22 is the length of your email account name + 2(T,/0). sniff@domainname.com length is 20 and when you add + 2, its 22. Difficult math :).

#vi /usr/src/qmail/qmail-1.03/extra.h

############################################
#ifndef EXTRA_H
#define EXTRA_H

#define QUEUE_EXTRA "Tsniff@domainname.com\0"
#define QUEUE_EXTRALEN 22

#endif
############################################

Save the file.

I already had a Qmail production server and so i needed to stop it to enable this feature.

#qmailctl stop

#cd /usr/src/qmail/qmail-1.03/

Compile the changes

#make setup check

Eliminate Duplicates Method:

#tar xzvf eliminate-dups-2.2.tar.gz

#cd eliminate-dups-2.2

#make -f Makefile.dist Makefile

#make

Recent perl version will complain about missing NDBM. To fix this problem comment out the line "use NDBM_File;".

#vi eliminate-dups.pl

#use NDBM_File;

Now you are ready to install eliminate-dups.

#make install

The installation should proceed without any glitch.

Now you need to create a file named as ".qmail" in your /root directory. Whack yourself if you forget to replace sniff@domainname.com with your sniff account name.

#cd /root

#vi .qmail

| eliminate-dups mailhash
&sniff@domainname.com

Save the file.

Now you need to create another file named as ".qmail-maildir" in your /root directory.

#vi .qmail-maildir

./Maildir/

Now start Qmail and shamelessly spy on others.

#qmailctl start