The web hosting publication by web hosting users for web hosting users
Update a Host / Editor Login
Search
Article News Host Business Name
DIRECTORY TOP RATING EDITOR REVIEW SEARCH HOSTING SHOWCASE BECOME AN EDITOR
RECENT NEWS
ICANN Decides To Expand Internet
Pingdom Adds Business Monitoring Plan
Apptix Offers Hosted VoIP Products
Hostway Offers Free Server Setup
FWHN Offers 3 Discount Programs
Hosting Networking Site Launches
Infinera Names Strategic Materials VP
Egenera Hosts Virtualization Webinar
ARTICLES
Co-location Hosting
Dedicated Servers
Domain Names
E-Commerce / Merchant Accounts / Payment Gateways
Free Web Hosting
General Web Hosting
Hosting Software & Control Panels
Managed Web Hosting
Programming
Reseller Hosting
Running a Web Hosting Business
Search Engine Optimization
Specific Web Hosting Provider or Company
Technical & Security
Useful Website Tools
Virtual Private Servers
Web Design & Content
Website Marketing Campaign
SEARCH ARTICLES
WEBHOST DIRECTORY
By Location

By Category
Application Hosting
Collocation Hosting
Dedicated Servers
Domain Name Registration
Ecommerce Hosting
Free Web Hosting
Reseller Domain Name Registration
Reseller Hosting
Shared Web Hosting
Virtual Private Servers
By Function
Windows Web hosting
PHP Web Hosting
Mysql Web Hosting
ASP Web Hosting
MS SQL Server Web Hosting
Coldfusion Web Hosting
MS FrontPage Web Hosting
Ecommerce Web Hosting
Cheap/Discount Web Hosting
Personal Web Hosting
Domain Name Web Hosting
A-Z Listing
Enter web host domain:




Articles
  You are here : Home Articles Technical & Security
Transferring Mails to a New Server
Submitted by Larry Anderson on | 184 reads

Transferring Mails to a New Server

What happens when your current mail server is not meeting your demand? You have to get something new to top the performance. Of course if it is as easy as everyone using POP, then we do not need to fret over it since with POP, you can just shut off the incoming mail port and wait long enough for everyone to download their share of mails and the server is empty. In most cases, it isn’t the case.

Nowadays, users tend to use IMAP. IMAP protocol keeps a copy of the emails in the server. 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 you may find after a year or so that nobody ever access it. 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 as the one below:

 

#!/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.



ARTICLES | NEWS | DIRECTORY | TOP REVIEWS| TOP RATINGS| SEARCH | SHOWCASE | UPDATE A HOST
OUR EDITORS | CONTACT US | ADVERTISING | TERMS OF AGREEMENT
© Copyright 2006 , The Web Hosting Herald. All rights reserved.