1

Just tried learning Apache Camel.

I am trying to read gmail inbox unread mail.

I got the code snippet while searching but not able to get success from it.

if someone point out the mistake,

    PollingConsumer pollingConsumer = null;
    CamelContext context = new DefaultCamelContext();

   Endpoint endpoint = context.getEndpoint("imaps://imap.gmail.com?username=" + mailId + "&password=" + password + "&delete=false&peek=false&unseen=true&consumer.delay=6000&closeFolder=false&disconnect=false");


    System.out.println("end point:"+endpoint);

    pollingConsumer = endpoint.createPollingConsumer();
    System.out.println("polling consumer:"+pollingConsumer);
    pollingConsumer.start();

    pollingConsumer.getEndpoint().createExchange();
    System.out.println("Exchange is created:");
    Exchange exchange = pollingConsumer.receive();
    System.out.println("pollingConsumer.receive()");

pollingConsumer.receive(); is getting blocked, I have unread mail in my mailbox. Also I tried pollingConsumer.receive(6000); but it returns null.

I enable IMAP access in Gmail settings. is there any thing I am missing?

Jayesh
  • 6,047
  • 13
  • 49
  • 81

1 Answers1

2

Let me write the solution, It will help someone facing similar issue .

Actually I have added java mail jar, but imap jar was missing and it was not displaying any error for this.

That is why I was not able to figure out the actual cause.

After browsing the parameters of "imaps://imap.gmail.com", I came across "debugMode" parameter which by default is false. when I added that parameter with value true, then it complained of missing jar on my console. After adding that jar thinks work perfectly.

Thanks for help.

Jayesh
  • 6,047
  • 13
  • 49
  • 81
  • What JDK, OS and application server are you using? And is it the imap.jar from com.sun.mail (http://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22com.sun.mail%22%20AND%20a%3A%22imap%22) ? – Claus Ibsen Dec 24 '14 at 08:53