2
votes

I am using java mail api for reading the mails (using imap). I have 2 different mail boxes to read.

Following is configuration used :-

Microsoft Exchange Server 2007

java mail  :- tried javamail-1.4 , javamail-1.5
imap.url=imapmail.somedomain.com
imap.port=143

mail.user1=user_id_doesnt_work
mail.pwd1=some_pwd

mail.user2=user_id_works
mail.pwd2=some_pwd

java code :-

private void loginInbox() throws MessagingException{

    Folder inbox = null;
    Properties mailProps =  mailProps = new Properties();

   mailProps.put("mail.store.protocol", "imapmail.somedomain.com");
   mailProps.put("mail.imap.starttls.enable", "true");
   mailProps.put("mail.imap.starttls.required", "true");

   Session session = Session.getDefaultInstance(mailProps);
   Store store = session.getStore();

   store.connect("imapmail.somedomain.com", 143, EMAILUSER, EMAILPWD);    //throws exception here

   inbox = store.getFolder(INBOX);
   inbox.open(Folder.READ_WRITE);

}

I am able to login to both mail boxes through browser ,with both user id and password (url = imapmail.somedomain.com )

> Using JavaMail :-

Using java mail 'mail.user2=user_id_works' , I am able to login to mail.

But When I use java mail 'mail.user1=user_id_doesnt_work' throws exception :

javax.mail.AuthenticationFailedException: AUTHENTICATE failed. at com.sun.mail.imap.IMAPStore.protocolConnect(IMAPStore.java:723) at javax.mail.Service.connect(Service.java:364)

Could be there any server settings for that particular user which prevents login attempt ? Any thoughts would be appreciated.

2
I suspect that EMAILUSER, EMAILPWD are wrongly populated in store.connect call.Ravindra babu

2 Answers

1
votes

It's not at all clear how your properties are being used since the code you posted ignores them. I'm assuming that's not really the code you're using.

Change Session.getDefaultInstance to Session.getInstance, as described in the list of common mistakes in the JavaMail FAQ.

0
votes

We had this issue at work today so I hope this helps some people.

Our container, Weblogic had two jars in it's path: Javamail 1.1 (I think) and javamail 1.4.1.

After switching debug on we saw that it was erroring out with InvalidAlgorithmParameterException. We switched to a newer version of javamail and the issue was resolved.