Here is the problem :

My client moved to another server, and they have changed domain name servers already. Old server is still active. Problem is that I have to migrate massive amount of email accounts, and another problem is they don't have cPanel credentials so my only option is to connect to each account individually and move the messages.

I wanted to use imapsync to do the migration but it can't connect to old server for some reason.

I have modified my hosts file on local machine and setup mail.domain.com to point to old ip address for smtp server and tried to connect with outlook and it worked (made sure it reads messages from the old server).

So I don't know why imapsync doesn't work since I've successfully connected with outlook on port 143.

This is how I ran the command (I'm running it from my server where I have also modified hosts file) :

imapsync --host1 mail.domain.com --user1 [email protected] -password1 pass --host2 localhost --user2 [email protected] --password2 pass

It connects successfully to my localhost but when it tries to connec to old server this is what I get :

Info: turned ON syncinternaldates, will set the internal dates (arrival dates) on host2 same as host1.
Host1: will try to use LOGIN authentication on host1
Host2: will try to use LOGIN authentication on host2
Host1: imap connexion timeout is 120 seconds
Host2: imap connexion timeout is 120 seconds
Host1: IMAP server [mail.domain.com] port [143] user [[email protected]]
Host2: IMAP server [localhost] port [143] user [[email protected]]
Host1: connecting and login on host1 [mail.domain.com] port [143] with user [[email protected]]
Host1 failure: can not open imap connection on host1 [mail.domain.com] with user [[email protected]]: Unable to connect to mail.domain.com:


I have scanned old mail server IP on port 143 with nmap and imap is running properly. I can connect to old server with outlook and fetch emails, but imapsync is saying he can't connect?


Just to note, I have tried connecting to mail server with out modifing hosts by using ip of old mail server but it didn't work.

  • Just a few troubleshooting tips. I know you said you connected using Outlook on 143 but have you double checked that you didn't have it at 143 then set up SSL (which changes port perhaps unnoticed?). Can you see the connection via Netstat? The other thing is that I believe there's specific encryption options in imapsync that you may be needing in there?
    – KevC
    Feb 27, 2017 at 4:24
  • I have tested this imapsync locally on my pc (kind of messy to set up on windows) and it works. It would seem like there is some kind of setup which prevents me from talking to other servers that listen on port 143 from my server. I'm not sure how to circumvent this. I'm guessing I could do some kind of tunnel but I don't know how to do that exactly.
    – Reygoch
    Feb 27, 2017 at 14:01

2 Answers 2


your example command says you are trying to sync mails to local machine which will not work unless you have a imap server which can be looked up via internet, also in your command --host2 should have a public imap server name not localhost. You could follow this article



nmap just says port 143 is open, it does not mean that imap works properly at all. Since you changed the server hostnames for host1, we can't help that much. This error can come from bad typo in hostname, bad link, firewall between. Try tls encryption with:

imapsync ... --tls1

or try ssl encryption with:

imapsync ... --ssl1 

If it doesn't work, it means the problem is the connection. Try a manual telnet with:

telnet mail.domain.com 143
A1 LOGIN [email protected] secret

Anyway "Unable to connect to mail.domain.com" means the connection (hostname or port or link) is the problem. telnet should show the same error.

  • tried it, doesn't work
    – Reygoch
    Feb 27, 2017 at 18:58
  • Your answer would be much more helpful if you could include some information about what the commands are supposed to do and why the asker should run the commands.
    – Jenny D
    Feb 27, 2017 at 19:09

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .