Ubuntu – imapsync – Authentication failed

g-suiteimapsyncperlUbuntu

I've deployed many Google Apps accounts and have used imapsync a number of times to migrate accounts to Google Apps.

This time however, no matter what I try imapsync refuses to work claiming my credentials are incorrect – I've checked them time and time again and they are 100% correct.

On Ubuntu 12, built from source, my command is:

imapsync --host1 myserver.com --user1 user1@server1.com --password1 mypassword1 -ssl1 --host2 imap.gmail.com --user2 user2@googleappsdomain.com --password2 mypassword2 -ssl2 -authmech2 PLAIN

Full output from the command:

get options: [1]
PID is 21316
$RCSfile: imapsync,v $ $Revision: 1.592 $ $Date:
With perl 5.14.2 Mail::IMAPClient  3.35
Command line used:
/usr/bin/imapsync --debug --host1 myserver.com --user1 user1@server1.com --password1 mypassword1 -ssl1 --host2 imap.gmail.com --user2 user2@googleapps.com --password2 mypassword2 -ssl2 -authmech2 PLAIN
Temp directory is /tmp
PID file is /tmp/imapsync.pid
Modules version list:
Mail::IMAPClient     3.35
IO::Socket           1.32
IO::Socket::IP       ?
IO::Socket::INET     1.31
IO::Socket::SSL      1.53
Net::SSLeay          1.42
Digest::MD5          2.51
Digest::HMAC_MD5     1.01
Digest::HMAC_SHA1    1.03
Term::ReadKey        2.30
Authen::NTLM         1.09
File::Spec           3.33
Time::HiRes          1.972101
URI::Escape          3.31
Data::Uniqid         0.12

IMAPClient 3.35
Info: turned ON syncinternaldates, will set the internal dates (arrival dates) on host2 same as host1.
Info: will try to use LOGIN authentication on host1
Info: will try to use PLAIN authentication on host2
Info: imap connexions timeout is 120 seconds
Host1: IMAP server [SERVER1] port [993] user [USER1]
Host2: IMAP server [imap.gmail.com] port [993] user [USER2]
Host1: * OK [CAPABILITY IMAP4rev1 LITERAL+ SASL-IR LOGIN-REFERRALS ID ENABLE AUTH=PLAIN AUTH=LOGIN] Dovecot ready.
Host1: SERVER1 says it has CAPABILITY for AUTHENTICATE LOGIN
Host1: success login on [SERVER1] with user [USER1] auth [LOGIN]
Host2: * OK Gimap ready for requests from MY-VPS 
Host2: imap.gmail.com says it has CAPABILITY for AUTHENTICATE PLAIN
Failure: error login on [imap.gmail.com] with user [USER2] auth [PLAIN]: 2 NO [AUTHENTICATIONFAILED] Invalid credentials (Failure)

I have tried -authmech2 LOGIN as well which returns:

Host2: imap.gmail.com says it has NO CAPABILITY for AUTHENTICATE LOGIN
Failure: error login on [imap.gmail.com] with user [user2@googleappsdomain.com] auth [LOGIN]: 2 NO [AUTHENTICATIONFAILED] Invalid credentials (Failure)

If anyone can shed some light on this I would greatly appreciate it.

Best Answer

Double check the credentials, so give it a 200% check. Follow the Janne advice of checking the credentials via a standard client like Thunderbird or Outlook or manually (see below).

Take care of quoting issues with special characters in passwords, use single quotes surrounding 'passwords' and users 'values'.

imapsync ... --password2 'secret' 

Other point, --authmech2 PLAIN or --authmech2 LOGIN are useless with Gmail now since imapsync already uses them by default. If the login works with a classical email client then it definitively means it is a character/quoting issue in the values. You can check a manual login with ncat or telnet-ssl like in this example (the client part to type is "a LOGIN ..." then "b LOGOUT"):

ncat --ssl -C  imap.gmail.com 993
* OK Gimap ready for requests from 78.196.254.58 q1mb175739668wix
a LOGIN "gilles.lamiral@gmail.com" "secret" 
* CAPABILITY IMAP4rev1 UNSELECT IDLE NAMESPACE QUOTA ID XLIST... ESEARCH
a OK gilles.lamiral@gmail.com Gilles Lamiral authenticated (Success)
b LOGOUT
* BYE LOGOUT Requested
b OK 73 good day (Success)

Also try to change the password if there are weird characters in it.

Related Topic