Sometimes we just have to move on. Your current mail server may just not be meeting your needs, so you've put up something new. But what about old mail? If your servers are identical (Sendmail to Sendmail, etc.) or use the same mailbox storage format, you may be able to just transfer files directly. If not, read on..
If everyone uses POP, there's usually not much to transfer, and if you can shut off incoming mail and just wait long enough for everyone to pop their mail, there won't be anything. But many people now use IMAP
It's actually sometime useful NOT to transfer anything. Many users let their mailboxes build up without ever deleting unneeded messages. If you can leave the old server on the network, they can always access their old mail if they need to, but they (and you) may find after a year or so that nobody ever has. You might then archive the messages "Just in case" and take down the old server.
If you do want to transfer messages, it can be as simple as running command line tools. The first thing to do is to set the old server to forward all mail to the new server. Exactly what you do to accomplish that depends on your server, but it should be easy. For sendmail, you'd set SMART_HOST and MAIL_HUB, or edit the aliases file and forward each user. For SME server, set the "Delegate Mail Server" in the Server Manager.
Transferring existing mail depends on the format it now uses. For example, Qmail stores messages in individual files. On an SME server (which uses Qmail) you could transfer "tony"'s current mail with just this:
cd /home/e-smith/files/users/tony/Maildir for i in * do cat $i | /var/qmail/bin/qmail-inject done
Repeating that for each directory would move all mail to the new server. However, it all ends up in the user's INBOX unless that server can apply rules to determine where to file it. To assist that, you may want to use a perl program instead. Something like this:
#!/usr/bin/perl
use Mail::Mailer;
@stuff=<>;
foreach (@stuff) {
$from=$_ if /^From:/;
$to=$_ if /^To:/;
$subject=$_ if /^Subject:/;
last if $subject;
}
$from=~ s/From: //;
$from=~ s/<//;
$from=~ s/>//;
$to=~ s/To: //;
$to=~ s/<//;
$to=~ s/>//;
$subject=~ s/^/*** FILE ME IN CUSTS ***/;
$mailer=Mail::Mailer->new();
$mailer->open({From =>$from,
To => $to,
Subject => $subject,
}) or die "Can't open $!\n";
foreach (@stuff) {
print $mailer $_;
}
$mailer=>close();
You'd adjust the modification to Subject appropriately, or add entirely new headers if desired.
If your mail is stored in Unix mailbox fashion, you need something to read the messages and break them up. While you could read the mailboxes directly, it's more portable to use tools like POP:
#!/usr/bin/perl
use Net::POP3;
$pop=Net::POP3->new('10.1.36.237') or die "$!";
$pop->login("tony","password");
$messages=$pop->list;
foreach $msg(keys %$messages) {
$message=$pop->get($msg);
foreach (@$message) {
#same basic idea as above,
}
}
You may need to get Net::POP3 from CPAN. There are similar modules for IMAP.
Bruce Garlock suggested that Mailsync might also be useful here.
Have you tried Searching this site?
Unix/Linux/Mac OS X support by phone, email or on-site: Support Rates
This is a Unix/Linux resource website. It contains technical articles about Unix, Linux and general computing related subjects, opinion, news, help files, how-to's, tutorials and more. We appreciate comments and article submissions.
Many of the products and books I review are things I purchased for my own use. Some were given to me specifically for the purpose of reviewing them. I resell or can earn commissions from the sale of some of these items. Links within these pages may be affiliate links that pay me for referring you to them. That's mostly insignificant amounts of money; whenever it is not I have made my relationship plain. I also may own stock in companies mentioned here. If you have any question, please do feel free to contact me.
Specific links that take you to pages that allow you to purchase the item I reviewed are very likely to pay me a commission. Many of the books I review were given to me by the publishers specifically for the purpose of writing a review. These gifts and referral fees do not affect my opinions; I often give bad reviews anyway.
We use Google third-party advertising companies to serve ads when you visit our website. These companies may use information (not including your name, address, email address, or telephone number) about your visits to this and other websites in order to provide advertisements about goods and services of interest to you. If you would like more information about this practice and to know your choices about not having this information used by these companies, click here.
Click here to add your comments
---January 11, 2005
I wonder if mailsync; http://mailsync.sourceforge.net/ could be used to do this as well. It looks like it could be another option for transferring a mailbox to a new machine.
--BruceGarlock
---January 11, 2005
I wonder if mailsync; http://mailsync.sourceforge.net/ could be used to do this as well. It looks like it could be another option for transferring a mailbox to a new machine.
--BruceGarlock
---January 11, 2005
Yes, looks like it could - thanks!
--TonyLawrence
Don't miss responses! Subscribe to Comments by RSS or by Email
Click here to add your comments
If you want a picture to show with your comment, go get a Gravatar