【问题标题】:Apache Camel reading unread mail from gmail accountApache Camel 从 gmail 帐户读取未读邮件
【发布时间】:2017-08-10 17:48:29
【问题描述】:

刚刚尝试学习 Apache Camel。

我正在尝试阅读 gmail 收件箱中的未读邮件。

我在搜索时得到了代码 sn-p 但无法从中获得成功。

如果有人指出错误,

    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(); 被阻止,我的邮箱中有未读邮件。 我也试过pollingConsumer.receive(6000);,但它返回null。

我在 Gmail 设置中启用了 IMAP 访问。有什么我想念的吗?

【问题讨论】:

  • 你是在代理后面运行这个吗?
  • 您的代码对我有用。问题出在骆驼之外。
  • 感谢Itsallas 和James 的帮助。我写了解决方案。这是我的错误。

标签: java email apache-camel pooling


【解决方案1】:

让我写一下解决方案,它将帮助面临类似问题的人。

其实我已经添加了 java 邮件 jar,但是 imap jar 丢失并且它没有显示任何错误。

这就是为什么我无法找出真正的原因。

浏览"imaps://imap.gmail.com"的参数后发现"debugMode"参数默认为false。当我添加值为 true 的参数时,它抱怨我的控制台上缺少 jar。添加该罐子后认为工作完美。

感谢您的帮助。

【讨论】:

  • 您使用的是什么 JDK、操作系统和应用服务器?是来自 com.sun.mail (search.maven.org/…) 的 imap.jar 吗?
猜你喜欢
  • 2017-11-14
  • 1970-01-01
  • 1970-01-01
  • 2016-07-07
  • 2013-11-17
  • 1970-01-01
  • 2011-10-14
  • 2014-04-19
  • 1970-01-01
相关资源
最近更新 更多