I'm facing an error using javaMail & IMAPS to read emails on email account of my company hosted in office 365.
I'm using this test class:
public class TestMail {
public static void main(String[] args) {
// TODO Auto-generated method stub
Properties props = System.getProperties();
props.put("mail.imaps.auth.plain.disable","true");
props.setProperty("mail.imaps.timeout", "100000");
props.setProperty("mail.imaps.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
props.setProperty("mail.imaps.socketFactory.fallback", "false");
props.setProperty("mail.imaps.ssl.enable", "true");
try {
Session session = Session.getInstance(props, null);
session.setDebug(true);
Store store = session.getStore("imaps");
store.connect("outlook.office365.com", 993, "my-name#mycompagny.com", "MY_PASSWORD");
System.out.println(store);
Folder inbox = store.getFolder("Inbox");
inbox.open(Folder.READ_ONLY);
Message messages[] = inbox.getMessages();
for(Message message:messages) {
System.out.println(message);
}
} catch (Exception e) {
e.printStackTrace();
System.exit(2);
}
}
}
I'm getting the following error:
DEBUG: setDebug: JavaMail version 1.4.7
DEBUG: getProvider() returning javax.mail.Provider[STORE,imaps,com.sun.mail.imap.IMAPSSLStore,Oracle]
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: disable AUTH=PLAIN
DEBUG IMAPS: trying to connect to host "outlook.office365.com", port 993, isSSL true
* OK The Microsoft Exchange IMAP4 service is ready. [UABSADIAUAAyADYANABDAEEAMAAwADAANAAuAEYAUgBBAFAAMgA2ADQALgBQAFIATwBEAC4ATwBVAFQATABPAE8ASwAuAEMATwBNAA==]
A0 CAPABILITY
* CAPABILITY IMAP4 IMAP4rev1 AUTH=PLAIN AUTH=XOAUTH2 SASL-IR UIDPLUS ID UNSELECT CHILDREN IDLE NAMESPACE LITERAL+
A0 OK CAPABILITY completed.
DEBUG IMAPS: AUTH: PLAIN
DEBUG IMAPS: AUTH: XOAUTH2
DEBUG IMAPS: protocolConnect login, host=outlook.office365.com, user=my-name#mycompagny.com, password=<non-null>
DEBUG IMAPS: LOGIN command trace suppressed
DEBUG IMAPS: LOGIN command result: A1 NO LOGIN failed.
javax.mail.AuthenticationFailedException: LOGIN failed.
at com.sun.mail.imap.IMAPStore.protocolConnect(IMAPStore.java:661)
at javax.mail.Service.connect(Service.java:295)
at com.afklm.bagdss.task.TestMail.main(TestMail.java:25)
Related
I have problem with randomly login failed. By one hour is happening 2-4 times, and similar time, for example: about 14:26, 14:48, 15:26, 15:49, etc.
I use JavaMail(ver. 1.5.6) to email processing. Mailbox is Microsoft Exchange.
Application run every 5 minute to connect to mailbox.
Pseudocode for email processing:
estabilishConncetion()
prepareMailbox()
downloadEmails()
moveEmailsToSOmething()
closeConnection()
Code connection is like this:
public void establishConnection() throws ConnectionException {
logger.info("Establish connection... ");
props = new Properties();
props.setProperty("mail.imaps.ssl.enable", "true");
props.setProperty("mail.imaps.port", 993);
props.setProperty("mail.imaps.timeout", 60000);
props.setProperty("mail.imaps.connectiontimeout",60000 );
props.put("mail.imaps.auth.plain.disable", "true");
props.put("mail.imaps.auth.ntlm.disable", "true");
props.put("mail.imaps.auth.gssapi.disable", "true");
props.setProperty("mail.debug", "true"); // only for test
Session session = Session.getInstance(props, new Authenticator(){
#Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(somename, somepassword);
}
});
try {
store = session.getStore("imaps");
store.connect(EmailServerAddress, EmailAddress,Password);
} catch (MessagingException e) {
throw new ConnectionException(" Problem occured when try connect to host: " + ServerAddress + " on address: " +EmailAddress);
}
logger.info("Connected to mailbox.");
}
Logging when connected:
DEBUG IMAPS: trying to connect to host "somehost", port 993, isSSL true]]
* OK The Microsoft Exchange IMAP4 service is ready.]]
A0 CAPABILITY]]
* CAPABILITY IMAP4 IMAP4rev1 AUTH=NTLM AUTH=GSSAPI AUTH=PLAIN
STARTTLS UIDPLUS CHILDREN IDLE NAMESPACE LITERAL+]]
A0 OK CAPABILITY completed.]]
DEBUG IMAPS: protocolConnect login, host=somehost,
user=someuser, password=]]
DEBUG IMAPS: mechanism LOGIN not supported by server]] DEBUG IMAPS:
LOGIN command trace suppressed]] DEBUG IMAPS: LOGIN command result: A1
OK LOGIN completed.]]
A2 CAPABILITY]] * CAPABILITY IMAP4 IMAP4rev1 AUTH=NTLM AUTH=GSSAPI
AUTH=PLAIN STARTTLS UIDPLUS CHILDREN IDLE NAMESPACE LITERAL+]]
A2 OK CAPABILITY completed.]]
DEBUG IMAPS: AUTH: NTLM]] Connected to mailbox.]]
Logging when not connected:
DEBUG IMAPS: trying to connect to host "somehost", port 993, isSSL
true]]
* OK The Microsoft Exchange IMAP4 service is ready.]]
A0 CAPABILITY]]
* CAPABILITY IMAP4 IMAP4rev1 AUTH=NTLM AUTH=GSSAPI AUTH=PLAIN
STARTTLS UIDPLUS CHILDREN IDLE NAMESPACE LITERAL+]]
A0 OK CAPABILITY completed.]]
DEBUG IMAPS: protocolConnect login, host=somehost, user=someuser,
password=]]
DEBUG IMAPS: mechanism LOGIN not supported by server]] DEBUG
IMAPS: LOGIN command trace suppressed]] DEBUG IMAPS: LOGIN command
result: A1 NO LOGIN failed.]] //trying to login one more time with
failure
I checked this and its ok in my code:
1. Using JavaMail to connect to IMAP getting "A1 NO LOGIN failed" exception
2. https://javaee.github.io/javamail/FAQ#Exchange-login
3. I have unit test realted with connection and they always passed
Any sollution, clues, how to better debug this? :)
I've seen several posts that offer a solution to something very similar to my situation but for whatever reason it does not work for me.
For example, here it's presented as a working sample illustrating OP's related problem and here as an actual answer.
I need to send e-mail as myself from my Exchange account via SMTP using SSO UserID and Password. This all happens in a restricted corporate environment.
From what I understand from the debug info I'm successfully connecting to an SMTP server and then fail user authentication with 530 5.7.1 Client was not authenticated. NTLM authentication itself seems to be enabled.
DEBUG:
DEBUG: setDebug: JavaMail version 1.5.4
DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Oracle]
DEBUG SMTP: useEhlo true, useAuth false
DEBUG SMTP: trying to connect to host "server.bank.com", port 25, isSSL false
220 server1.corp.bank.com Microsoft ESMTP MAIL Service ready at Mon, 24 Aug 2015 17:15:24 -0400
DEBUG SMTP: connected to host "server.bank.com", port: 25
EHLO server2.corp.bank.com
250-server1.corp.bank.com Hello [xxx.xxx.xxx.xxx]
250-SIZE
250-PIPELINING
250-DSN
250-ENHANCEDSTATUSCODES
250-X-ANONYMOUSTLS
250-AUTH NTLM LOGIN
250-X-EXPS GSSAPI NTLM
250-8BITMIME
250-BINARYMIME
250-CHUNKING
250-XEXCH50
250-XRDST
250 XSHADOW
DEBUG SMTP: Found extension "SIZE", arg ""
DEBUG SMTP: Found extension "PIPELINING", arg ""
DEBUG SMTP: Found extension "DSN", arg ""
DEBUG SMTP: Found extension "ENHANCEDSTATUSCODES", arg ""
DEBUG SMTP: Found extension "X-ANONYMOUSTLS", arg ""
DEBUG SMTP: Found extension "AUTH", arg "NTLM LOGIN"
DEBUG SMTP: Found extension "X-EXPS", arg "GSSAPI NTLM"
DEBUG SMTP: Found extension "8BITMIME", arg ""
DEBUG SMTP: Found extension "BINARYMIME", arg ""
DEBUG SMTP: Found extension "CHUNKING", arg ""
DEBUG SMTP: Found extension "XEXCH50", arg ""
DEBUG SMTP: Found extension "XRDST", arg ""
DEBUG SMTP: Found extension "XSHADOW", arg ""
DEBUG SMTP: use8bit false
MAIL FROM:<first.last#bank.com>
530 5.7.1 Client was not authenticated
DEBUG SMTP: got response code 530, with response: 530 5.7.1 Client was not authenticated
Essential part of my code:
static void sendEmail(){
Properties props = System.getProperties();
props.setProperty("mail.smtp.host", host);
props.setProperty("mail.smtp.port", "25");
// props.setProperty("mail.debug", "true");
// props.setProperty("mail.debug.auth", "true");
props.setProperty("mail.smtp.starttls.enable","true");
props.setProperty("mail.smtp.auth.mechanisms", "NTLM");
props.setProperty("mail.smtp.auth.ntlm.domain", user_sso_domain);
// Session session = Session.getDefaultInstance(props);
Session session = Session.getDefaultInstance(props,
new javax.mail.Authenticator() {
#Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(user_sso_id, user_sso_password);
}
});
session.setDebug(true);
try {
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(email_from));
message.addRecipient(Message.RecipientType.TO,
new InternetAddress(email_to));
message.setSubject("Test Message");
message.setText("This is my test message");
Transport.send(message);
} catch (Exception ex) {
ex.printStackTrace();
}
}
I would appreciate your suggestions for further troubleshooting.
EDIT
Working code after implementing the fix and better practices from the accepted answer:
private static void sendEmail(){
Properties props = System.getProperties();
props.setProperty("mail.smtp.host", host);
props.setProperty("mail.smtp.port", "25");
// props.setProperty("mail.debug", "true");
// props.setProperty("mail.debug.auth", "true");
props.setProperty("mail.smtp.auth", "true");
props.setProperty("mail.smtp.starttls.enable","true");
props.setProperty("mail.smtp.auth.mechanisms", "NTLM");
props.setProperty("mail.smtp.auth.ntlm.domain", user_sso_domain);
Session session = Session.getInstance(props);
session.setDebug(true);
try {
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(email_from));
message.addRecipient(Message.RecipientType.TO,
new InternetAddress(email_to));
message.setSubject("Test Message");
message.setText("This is my test message");
Transport.send(message, user_sso_id, user_sso_password);
} catch (Exception ex) {
ex.printStackTrace();
}
}
You need to set "mail.smtp.auth" to "true".
Or, better yet, fix these common mistakes and make your program much simpler.
I'm writing a program that connects to gmail and checks the number of messages in the inbox. If I call getMessageCount() on the unopened Folder, it returns 554, but after opening it, it returns 541. Why the difference?
By the way, I'm ultimately trying to check for deleted messages (that have not been expunged) and recover them if possible.
Edit: some example code:
Session session = Session.getDefaultInstance(System.getProperties());
Store store = session.getStore("imaps");
store.connect("imap.googlemail.com", 993, email, password);
Folder inbox = store.getFolder("INBOX");
System.out.println(inbox.getMessageCount());
inbox.open(Folder.READ_ONLY);
System.out.println(inbox.getMessageCount());
Edit: protocol trace:
(In the meantime I got some more emails so the numbers are different from above)
DEBUG: setDebug: JavaMail version 1.5.2
DEBUG: getProvider() returning javax.mail.Provider[STORE,imaps,com.sun.mail.imap.IMAPSSLStore,Oracle]
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: trying to connect to host "imap.googlemail.com", port 993, isSSL true
* OK Gimap ready for requests from <ip> vt17mb17567619iec
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! vt17mb17567619iec
DEBUG IMAPS: AUTH: XOAUTH
DEBUG IMAPS: AUTH: XOAUTH2
DEBUG IMAPS: AUTH: PLAIN
DEBUG IMAPS: AUTH: PLAIN-CLIENTTOKEN
DEBUG IMAPS: protocolConnect login, host=imap.googlemail.com, user=<email>, password=<non-null>
DEBUG IMAPS: AUTHENTICATE PLAIN command trace suppressed
DEBUG IMAPS: AUTHENTICATE PLAIN command result: A1 OK <email> authenticated (Success)
A2 CAPABILITY
* CAPABILITY IMAP4rev1 UNSELECT IDLE NAMESPACE QUOTA ID XLIST CHILDREN X-GM-EXT-1 UIDPLUS COMPRESS=DEFLATE ENABLE MOVE CONDSTORE ESEARCH UTF8=ACCEPT
A2 OK Success
A3 LIST "" INBOX
* LIST (\HasChildren) "/" "INBOX"
A3 OK Success
A4 STATUS INBOX (MESSAGES RECENT UNSEEN UIDNEXT UIDVALIDITY)
* STATUS "INBOX" (MESSAGES 585 RECENT 0 UIDNEXT 3389 UIDVALIDITY 2 UNSEEN 0)
A4 OK Success
585
DEBUG IMAPS: connection available -- size: 1
A5 EXAMINE INBOX
* FLAGS (\Answered \Flagged \Draft \Deleted \Seen $Phishing $Forwarded NonJunk $NotPhishing Junk)
* OK [PERMANENTFLAGS ()] Flags permitted.
* OK [UIDVALIDITY 2] UIDs valid.
* 548 EXISTS
* 0 RECENT
* OK [UIDNEXT 3389] Predicted next UID.
* OK [HIGHESTMODSEQ 687472]
A5 OK [READ-ONLY] INBOX selected. (Success)
548
I am using velocity to generate HTML template based content for the email which is to be sent, and Java Mail API with Spring's MimeMessageHelper to send emails. The problem i am facing is that while rendering, HTML template is thrown to catalina.out which is making the file grow in size and that is not desirable.
I have a separate application log file where the logs are generated. Is there any way so that I can redirect this rendering to my application log file? Or may be I can stop this to be thrown at catalina.out.
Below is the details which gets written while sending email
Loading javamail.default.providers from jar:file:/D:/workspace/EmailService/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/email-service/WEB-INF/lib/mail-1.4.jar!/META-INF/javamail.default.providers
DEBUG: loading new provider protocol=imap, className=com.sun.mail.imap.IMAPStore, vendor=Sun Microsystems, Inc, version=null
DEBUG: loading new provider protocol=imaps, className=com.sun.mail.imap.IMAPSSLStore, vendor=Sun Microsystems, Inc, version=null
DEBUG: loading new provider protocol=smtp, className=com.sun.mail.smtp.SMTPTransport, vendor=Sun Microsystems, Inc, version=null
DEBUG: loading new provider protocol=smtps, className=com.sun.mail.smtp.SMTPSSLTransport, vendor=Sun Microsystems, Inc, version=null
DEBUG: loading new provider protocol=pop3, className=com.sun.mail.pop3.POP3Store, vendor=Sun Microsystems, Inc, version=null
DEBUG: loading new provider protocol=pop3s, className=com.sun.mail.pop3.POP3SSLStore, vendor=Sun Microsystems, Inc, version=null
DEBUG: getProvider() returning provider protocol=smtp; type=javax.mail.Provider$Type#2025b64d; class=com.sun.mail.smtp.SMTPTransport; vendor=Sun Microsystems, Inc
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: trying to connect to host "smtp.nagarro.com", port 587, isSSL false
220 fuseout2c MailAnyone extSMTP Tue, 23 Jul 2013 02:37:58 -0700
DEBUG SMTP: connected to host "smtp.nagarro.com", port: 587
EHLO Vaibhav202001
250-fuseout2c Hello Vaibhav202001 [14.141.12.161]
250-SIZE 52428800
250-PIPELINING
250-AUTH LOGIN
250-STARTTLS
250 HELP
DEBUG SMTP: Found extension "SIZE", arg "52428800"
DEBUG SMTP: Found extension "PIPELINING", arg ""
DEBUG SMTP: Found extension "AUTH", arg "LOGIN"
DEBUG SMTP: Found extension "STARTTLS", arg ""
DEBUG SMTP: Found extension "HELP", arg ""
STARTTLS
220 TLS go ahead
EHLO Vaibhav202001
250-fuseout2c Hello Vaibhav202001 [14.141.12.161]
250-SIZE 52428800
250-PIPELINING
250-AUTH LOGIN
250 HELP
DEBUG SMTP: Found extension "SIZE", arg "52428800"
DEBUG SMTP: Found extension "PIPELINING", arg ""
DEBUG SMTP: Found extension "AUTH", arg "LOGIN"
DEBUG SMTP: Found extension "HELP", arg ""
DEBUG SMTP: Attempt to authenticate
AUTH LOGIN
334 VXNlcm5hbWU6
anNhZy5zdXBwb3J0QG5hZ2Fycm8uY29t
334 UGFzc3dvcmQ6
SnNhZ0AxMjM0
235 Authentication succeeded
DEBUG SMTP: use8bit false
MAIL FROM:<jsagteam#nagarro.com>
250 OK
RCPT TO:<vaibhav.shukla#nagarro.com>
250 Accepted
DEBUG SMTP: Verified Addresses
DEBUG SMTP: vaibhav.shukla#nagarro.com
DATA
354 Enter message, ending with "." on a line by itself
Date: Fri, 26 Jul 2013 12:00:48 +0530 (IST)
From: JSAG Team <jsagteam#nagarro.com>
To: vaibhav.shukla#nagarro.com
Message-ID: <1817391686.01374820248531.JavaMail.vaibhav2020#Vaibhav202001>
Subject: JSAG Home page - subscribers list
MIME-Version: 1.0
Content-Type: multipart/mixed;
boundary="----=_Part_0_999692932.1374820244866"
------=_Part_0_999692932.1374820244866
Content-Type: multipart/related;
boundary="----=_Part_1_1241615899.1374820244889"
------=_Part_1_1241615899.1374820244889
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit
//My Email Template goes here
------=_Part_1_1241615899.1374820244889--
------=_Part_0_999692932.1374820244866--
250 OK id=1V1Z2g-0002Rh-HO
QUIT
221 fuseout2c closing connection
And here is the logging configuration
log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=${catalina.home}/logs/email-service.log
log4j.appender.file.MaxFileSize=1000KB
log4j.appender.file.MaxBackupIndex=1
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-4p %m%n
log4j.appender.DatePattern='.'yyyy-MM-dd
# Root logger option
log4j.rootLogger=WARN, file
log4j.logger.com.nagarro=WARN
Also the code to send email
JavaMailSender mailSender; // injected through Spring DI
/**
* The mail message.
*/
SimpleMailMessage mailMessage; // Spring DI
#Override
public void sendEMail(final EmailServiceRequest request, byte[] data) {
MimeMessage message = mailSender.createMimeMessage();
OutputStream outStream = null;
try {
MimeMessageHelper helper = new MimeMessageHelper(message, true);
// set attributes
if (null != request.getRecipientEmailId()) {
helper.setTo(request.getRecipientEmailId());
}
helper.setFrom(request.getSenderEmailId());
helper.setSubject(request.getSubject());
helper.setText(request.getContent(), true);
// check for recipient list
if (null != request.getRecipients() && !request.getRecipients().isEmpty()) {
InternetAddress[] recipients = new InternetAddress[request.getRecipients().size()];
for (int index = 0; index < request.getRecipients().size(); index++) {
recipients[index] = new InternetAddress(request.getRecipients().get(index));
}
helper.setTo(recipients);
}
// data handler
if (null != data) {
try {
File file = File.createTempFile(request.getAttachmentName(), "");
outStream = new FileOutputStream(file);
outStream.write(data);
helper.addAttachment(request.getAttachmentName(), file);
} catch (IOException e) {
logger.error(e.getMessage(), e);
} finally {
try {
outStream.flush();
outStream.close();
} catch (IOException e) {
logger.error(e.getMessage(), e);
}
}
}
if (!StringUtil.isNullOrEmpty(request.getEmailIdCC())) {
helper.addCc(request.getEmailIdCC());
}
if (!StringUtil.isNullOrEmpty(request.getEmailIdBCC())) {
helper.addBcc(request.getEmailIdBCC());
}
mailSender.send(message);
} catch (MessagingException e) {
logger.error(e.getLocalizedMessage(), e);
}
}
I assume you have defined a bean with class org.springframework.mail.javamail.JavaMailSenderImpl in your context configuration.
If so, you could try to set the debug property on the session.
mailSender.getSession().setDebug(false);
Or create a properties file and set set the value there.
mail.debug=false
I am trying to use oauth to access my inbox, I always get invalid credential error when I use token generated using my JAVA code. I am using IMAP and passing oauth token to get authenticated. But when I generate token using python and use the same in my code, it works fine and fetch emails from my Inbox.
Here is the code snippet using IMAP:
public static IMAPSSLStore connectToImap(String host,
int port,
String userEmail,
String oauthToken,
String oauthTokenSecret,
OAuthConsumer consumer,
boolean debug) throws Exception {
Properties props = new Properties();
props.put("mail.imaps.sasl.enable", "true");
props.put("mail.imaps.sasl.mechanisms", "XOAUTH");
props.put(XoauthSaslClientFactory.OAUTH_TOKEN_PROP,
oauthToken);
props.put(XoauthSaslClientFactory.OAUTH_TOKEN_SECRET_PROP,
oauthTokenSecret);
props.put(XoauthSaslClientFactory.CONSUMER_KEY_PROP,
consumer.consumerKey);
props.put(XoauthSaslClientFactory.CONSUMER_SECRET_PROP,
consumer.consumerSecret);
Session session = Session.getInstance(props);
session.setDebug(debug);
final URLName unusedUrlName = null;
IMAPSSLStore store = new IMAPSSLStore(session, unusedUrlName);
final String emptyPassword = "anonymous";
store.connect(host, port, userEmail, emptyPassword);
return store;
}
Here is the error log -
DEBUG: setDebug: JavaMail version 1.3.3
1
2
DEBUG: mail.imap.fetchsize: 16384
DEBUG: enable SASL
DEBUG: SASL mechanisms allowed: XOAUTH
3
4
* OK Gimap ready for requests from 122.179.85.133 kn10if6680532igc.14
A0 CAPABILITY
* CAPABILITY IMAP4rev1 UNSELECT IDLE NAMESPACE QUOTA ID XLIST CHILDREN X-GM-EXT-1 XYZZY SASL-IR AUTH=XOAUTH
A0 OK Thats all she wrote! kn10if6680532igc.14
IMAP DEBUG: AUTH: XOAUTH
DEBUG: protocolConnect login, host=imap.googlemail.com, user=me#mydomain.com, password=<non-null>
IMAP SASL DEBUG: Mechanisms: XOAUTH
IMAP SASL DEBUG: SASL client XOAUTH
A1 AUTHENTICATE XOAUTH
+
IMAP SASL DEBUG: challenge: :
IMAP SASL DEBUG: callback length: 1
IMAP SASL DEBUG: callback 0: javax.security.auth.callback.NameCallback#d1e832
IMAP SASL DEBUG: response: GET https://mail.google.com/mail/b/me#mydomain.com/imap/ oauth_signature_method="HMAC-SHA1",oauth_token="1%2Furn42qGc5mpD3BwVvJMzeVkHl_9iVRCZvaSOYmKNH5A",oauth_consumer_key="mydomain.com",oauth_timestamp="1329301212",oauth_nonce="629121335212995",oauth_version="1.0",oauth_signature="7O1YHXywiqOX8XzSAd%2BzbmDoBVw%3D" :
R0VUIGh0dHBzOi8vbWFpbC5nb29nbGUuY29tL21haWwvYi9wZXRlckBhMm9tb2JpbGUuY29tL2ltYXAvIG9hdXRoX3NpZ25hdHVyZV9tZXRob2Q9IkhNQUMtU0hBMSIsb2F1dGhfdG9rZW49IjElMkZ1cm40MnFHYzVtcEQzQndWdkpNemVWa0hsXzlpVlJDWnZhU09ZbUtOSDVBIixvYXV0aF9jb25zdW1lcl9rZXk9ImEyb21vYmlsZS5jb20iLG9hdXRoX3RpbWVzdGFtcD0iMTMyOTMwMTIxMiIsb2F1dGhfbm9uY2U9IjYyOTEyMTMzNTIxMjk5NSIsb2F1dGhfdmVyc2lvbj0iMS4wIixvYXV0aF9zaWduYXR1cmU9IjdPMVlIWHl3aXFPWDhYelNBZCUyQnpibURvQlZ3JTNEIg==
5
DEBUG: connection available -- size: 1
A2 EXAMINE INBOX
A1 NO [ALERT] Invalid credentials (Failure)
A2 BAD Unknown command r5if6689112igo.50
A3 LOGOUT
* BYE Logout Requested r5if6689112igo.50
A3 OK Quoth the raven, nevermore... r5if6689112igo.50
Exception in thread "main" javax.mail.MessagingException: A2 BAD Unknown command r5if6689112igo.50;
nested exception is:
com.sun.mail.iap.BadCommandException: A2 BAD Unknown command r5if6689112igo.50
at com.sun.mail.imap.IMAPFolder.open(IMAPFolder.java:820)
at com.a2o.service.collaboration.common.XoauthAuthenticator.getMessages(XoauthAuthenticator.java:238)
at com.a2o.service.collaboration.common.XoauthAuthenticator.main(XoauthAuthenticator.java:205)
Is there any way to generate token properly from JAVA code. My actual requirement is to generate token using my iPad client and fetch emails using that token in my server. Any help is highly appriciated.
we have used http://pastebin.com/kwcZQcvj to create token and secret.