2

I'm trying to migrate a client's hosting from a really bad host to a new one.

The current host provides no control panel (they're a bit control freaks, you have to lodge a ticket to do anything) so I can't back up the mail from the control panel.

I need a way to grab the mail from the mailboxes and transfer it onto the new host.

As far as I know, they only provide pop3 on their server either so I can't use imapsync.

The new host is a vps with cpanel, I can install whatever could help on it.

Is there any way that I can automate the transfer from the old host to the new one?

Am I doomed?

Ben
  • 367
  • 3
  • 21
  • What kind of mail server do you plan on running on the new host? – Handyman5 Aug 25 '11 at 01:36
  • @Handyman5 - it's a CentOS with cPanel vps, so I'm guessing exim. – Ben Aug 25 '11 at 02:02
  • 2
    Most POP clients will download the mail from the server and store it locally within the mail client, so in most cases there wouldn't be any mail stored on the server to migrate. Some clients have an option to keep a copy on the server (sometimes forever, sometimes for X days), but even if the copy on the server goes away the client will generally retain a local copy of the message regardless of what the server does on its end. Usually in a pure-POP environment you can just migrate the accounts and point the client to the new server with no loss of stored mail. – Justin Scott Aug 25 '11 at 04:09
  • @Justin. Except that some users only access their mail through webmail. – Ben Aug 25 '11 at 06:10
  • @Ben but that you have webmail was not in your specification... – mailq Aug 25 '11 at 19:16
  • @mailq. Does it matter? The question was clearly asking how to move mail with just pop3, not about starting a debate whether it's worth doing – Ben Aug 26 '11 at 03:24
  • Sorry, I wasn't trying to start a debate, just providing some additional information for future passers-by who may not have as much experience with the matter. Webmail brings up other considerations. In my experience many webmail front-ends will use IMAP to communicate with the server to maintain folders and sorted mail, read status, etc. all synched with other clients accessing the mailbox. In POP-only webmail clients, the ones I've worked with will pull the mail into the webmail app and use its own data store just like a standard mail client would since POP has no concept of folders. – Justin Scott Aug 27 '11 at 23:59

3 Answers3

4

If you use a Unix/Linux solution (like Postfix/Dovecot), you could just use fetchmail or something like that to get the mails from the old server and inject it into the local mail system on the new one.

All you would need is a list of usernames/passwords for the POP accounts on the old server.

Sven
  • 97,248
  • 13
  • 177
  • 225
  • @SvenW.. ok, _interesting_.. can you recommend a good tutorial/example on using fetchmail? – Ben Aug 25 '11 at 02:04
  • The fetchmail man page is actually quite good and informative and even has config examples: http://www.fetchmail.info/fetchmail-man.html#42 – Sven Aug 25 '11 at 08:03
  • @SvenW.. Yes, I agree with that. Was actually reading it at lunch time and it seems nicely written. It sounds like I could write 1 single config file on the new vps and call fetchmail once and it will dispatch each remote account to a different local account (which would be perfect). It advises itself against running as root - do you think there would be any issue doing it as root since it's running only once? (don't really want to login into each local mail account to download the mail once.. ) – Ben Aug 25 '11 at 10:40
  • Yes, one config file is sufficient, and running as root for this purpose is OK as well, this hint is more concerned with the daemon mode that fetchmail also supports or the call from a crontab. BTW, since this migration can be tricky to get right, I would suggest you make sure mails don't get deleted on the source machine and create some dummy accounts on the target machine where you will drop the mails and delete them afterwards if everything is working as expected. – Sven Aug 25 '11 at 12:12
  • Yes, very good advice. I did notice the "keep" statement on the man page and I definitely will do tests and keep on the old server. Thanks for your help, I feel way more knowledgeable :) – Ben Aug 25 '11 at 12:20
3

SvenW's answer was spot on helpful, thanks!

For those interested here are the details of the command to run.

Notes:

  1. i'm running this as root on the new server

  2. A fetchmailrc file is not necessary, can be all done with one command (since it's once off it's good)

  3. Password are not passed on the command line, so the first step is to create a .netrc in the home folder with the following syntax:

    machine server.com

    login email@server.com

    password thepassword

If you need multiple, just keep adding them in the netrc file.

  1. Run this command

    fetchmail -v -a -k -p APOP -S localhost --smtpname email@server.com -u email@server.com server.com

    -v makes it more verbose, helpful

    -a grabs everything (including read email)

    -k keep mail on the old server (up to you, may be good for testing)

    -p the protocol to use. APOP worked for me, but check the fetchmail documentation

    -S (that's uppercase S) the destination server (localhost since i'm already on the machine)

    --smtpname the local recipient (should be the same mailbox as the source server)

    -u the username to connect to the remote server (some servers use email@server.com, some just email, or sometimes something else)

    and finally the last server.com is the address of the remote (old) server

for testing you can also add a -c parameter, that checks but doesn't retrieve. Good way to check if the setup is correct

Ben
  • 367
  • 3
  • 21
3

pop2imap is designed to transfer messages from a pop3 server to an imap server incrementally. Same usage as imapsync.

http://www.linux-france.org/prj/pop2imap/

pop2imap \
   --host1 pop3.troc.org --user1 foo --password1 secret1 \
   --host2 imap.trac.org --user2 bar --password2 secret2
Gilles LAMIRAL
  • 405
  • 2
  • 7
  • Thanks for the suggestion. Managed to do it with fetchmail but i'm sure some others will find that tool handy – Ben Aug 30 '11 at 00:38