Connect to GMail using JavaMail

521 views
Skip to first unread message

di...@nubbius.com

unread,
May 16, 2014, 6:49:46 AM5/16/14
to google-a...@googlegroups.com
Hello,

I want to connect to GMail using JavaMail 1.5.2. I have two kind of clients: for one hand, there're clients who use OAuth 2.0 2-legged (service account) and they connect to GMail and they can get the messages fine. For another hand, there're clients who use OAuth 2.0 3-legged (normal identification). I can't connect with them to GMail. 


The Java code that I'm using to connect is:

 Properties props = new Properties();
 props.put("mail.imap.ssl.enable", "true"); 
 props.put("mail.imap.sasl.enable", "true");
 props.put("mail.imap.sasl.mechanisms", "XOAUTH2");
 props.put("mail.imap.auth.login.disable", "true");
 props.put("mail.imap.auth.plain.disable", "true");
 Session session = Session.getInstance(props);
 Store store = session.getStore("imap");
 store.connect("imap.gmail.com", email, access_token);

When I try this code, my debug says:

DEBUG: setDebug: JavaMail version 1.5.2
DEBUG IMAPS: mail.imap.fetchsize: 16384
DEBUG IMAPS: mail.imap.ignorebodystructuresize: false
DEBUG IMAPS: mail.imap.statuscachetimeout: 1000
DEBUG IMAPS: mail.imap.appendbuffersize: -1
DEBUG IMAPS: mail.imap.minidletime: 10
DEBUG IMAPS: enable SASL
DEBUG IMAPS: SASL mechanisms allowed: XOAUTH2
DEBUG IMAPS: trying to connect to host "imap.gmail.com", port 993, isSSL true
* OK Gimap ready for requests from XX.XX.XX.XX pg7mb36974204wic
A0 CAPABILITY
* CAPABILITY IMAP4rev1 UNSELECT IDLE NAMESPACE QUOTA ID XLIST CHILDREN X-GM-EXT-1 XYZZY SASL-IR AUTH=XOAUTH AUTH=XOAUTH2 AUTH=PLAIN AUTH=PLAIN-CLIENTTOKEN
A0 OK Thats all she wrote! pg7mb36974204wic
DEBUG IMAPS: AUTH: XOAUTH
DEBUG IMAPS: AUTH: XOAUTH2
DEBUG IMAPS: AUTH: PLAIN
DEBUG IMAPS: AUTH: PLAIN-CLIENTTOKEN
DEBUG IMAPS: protocolConnect login, host=imap.gmail.com, user=MY_EMAILs, password=<non-null>
DEBUG IMAPS: SASL authentication command trace suppressed
DEBUG IMAPS: SASL Mechanisms:
DEBUG IMAPS:  XOAUTH2
DEBUG IMAPS: 
DEBUG IMAPS: SASL client XOAUTH2
DEBUG IMAPS: SASL callback length: 1
DEBUG IMAPS: SASL callback 0: javax.security.auth.callback.NameCallback@138bef5
DEBUG IMAPS: SASL no response

Well, I don't know what happens but it has to be because of OAuth 2.0 because I have tried to connect to GMail without OAuth 2.0 (using email and password) and it works fine.

Any idea?

___
Nota:
 Según la normativa vigente en materia de Protección de Datos de Carácter Personal, le informamos que sus datos han sido incorporados a un fichero denominado "Clientes y/o Proveedores" creado por resolución de la Agencia Española de Protección de Datos y del que es responsable "The Cloud Gate S.L.", con CIF: B-18961433. La finalidad del tratamiento de sus datos es mantener la relación contractual existente o mantenerle informado de novedades y noticias que puedan resultar de su interés. Le informamos que usted puede ejercitar sus derechos de acceso, rectificación, cancelación y oposición, mediante escrito dirigido a: "The Cloud Gate S.L.", Avda. Constitución 22, 1º 8 - 18012 Granada, o mediante email a la siguiente dirección de correo electrónico: in...@thecloud.es La información incluida en este e-mail es CONFIDENCIAL, siendo para uso exclusivo del destinatario arriba mencionado. Si usted lee este mensaje y no es el destinatario indicado, le informamos que está totalmente prohibida cualquier utilización, divulgación, distribución y/o reproducción de esta comunicación sin autorización expresa en virtud de la legislación vigente. Si ha recibido este mensaje por error, le rogamos nos lo notifique inmediatamente por esta misma vía y proceda a su eliminación. "
nubbius" es una marca registrada por The Cloud Gate S.L.

This information is private and confidential and intended for the recipient only. If you are not the intended recipient of this message you are hereby notified that any review, dissemination, distribution or copying of this message is strictly prohibited. This communication is for information purposes only and should not be regarded as an official statement from The Cloud Gate, S.L. Email transmission cannot be guaranteed to be secure or error-free. Therefore, we do not represent that this information is complete or accurate and it should not be relied upon as such. All information is subject to change without notice. 
"nubbius" is a registered trademark of The Cloud Gate S.L.

Vinny P

unread,
May 18, 2014, 2:55:01 AM5/18/14
to google-a...@googlegroups.com
On Fri, May 16, 2014 at 5:49 AM, <di...@nubbius.com> wrote:
For another hand, there're clients who use OAuth 2.0 3-legged (normal identification). I can't connect with them to GMail. 


Are all client accounts failing the 3-legged OAuth, or are there some accounts that work properly and some that do not? Can you construct a simple test case that fails for you, yet you expect it to work? Finally, what scope did you request when collecting the access token?


On Fri, May 16, 2014 at 5:49 AM, <di...@nubbius.com> wrote:
Well, I don't know what happens but it has to be because of OAuth 2.0 because I have tried to connect to GMail without OAuth 2.0 (using email and password) and it works fine.


Did you try using username/password with the same accounts that are failing the 3-legged OAuth login?  
 
 
-----------------
-Vinny P
Technology & Media Advisor
Chicago, IL

App Engine Code Samples: http://www.learntogoogleit.com

Reply all
Reply to author
Forward
0 new messages