如何使用Apache Camel轮询我的谷歌邮件收件箱中的邮件?

时间:2017-03-12 19:32:06

标签: java gmail apache-camel polling

我正在尝试学习如何使用Apache Camel,目前我想尝试在我的Google邮件收件箱中查看邮件。

为此,我首先尝试了Apache Camel的Mail组件文档中提供的以下示例:

from("imaps://imap.gmail.com?username=YOUR_USERNAME@gmail.com&password=YOUR_PASSWORD"
    + "&delete=false&unseen=true&consumer.delay=60000").to("log:newmail");

这是我的代码:

public static void main(String[] args) throws Exception
{
    // create CamelContext
    CamelContext context = new DefaultCamelContext();

    // add our route to the CamelContext
    context.addRoutes(new RouteBuilder()
    {
        public void configure()
        {
            from("imap://imap.gmail.com?username=YOUR_USERNAME@gmail.com&password=YOUR_PASSWORD"
                + "&delete=false&unseen=true&consumer.delay=10000").to("log:newmail");
        }
    });

    // start the route and let it do its work
    context.start();
    Thread.sleep(60000);

    // stop the CamelContext
    context.stop();
}

在相应的字段中输入我的用户名和正确的密码后,我使用maven编译并执行了我的代码:

mvn clean compile exec:java -Dexec.mainClass=natan.apps.ApacheCamelDemo

我在我的控制台中获得以下内容:

[ead #0 - imap://imap.gmail.com] MailConsumer                   DEBUG Connecting to MailStore: imap://imap.gmail.com:143, folder=INBOX
[ead #0 - imap://imap.gmail.com] MailConsumer                   WARN  Consumer Consumer[imap://imap.gmail.com?consumer.delay=10000&delete=false&password=xxxxxx&unseen=true&username=natan.daniel0%40gmail.com] failed polling endpoint: imap://imap.gmail.com?consumer.delay=10000&delete=false&password=xxxxxx&unseen=true&username=natan.daniel0%40gmail.com. Will try again at next poll. Caused by: [javax.mail.MessagingException - * BYE Cannot connect to IMAP server ::ffff:64.233.166.108 (::ffff:64.233.166.108:143), connect error 10060]
javax.mail.MessagingException: * BYE Cannot connect to IMAP server ::ffff:64.233.166.108 (::ffff:64.233.166.108:143), connect error 10060;
  nested exception is:
        com.sun.mail.iap.ConnectionException: * BYE Cannot connect to IMAP server ::ffff:64.233.166.108 (::ffff:64.233.166.108:143), connect error 10060
        at com.sun.mail.imap.IMAPStore.protocolConnect(IMAPStore.java:723)[javax.mail-1.5.5.jar:1.5.5]
        at javax.mail.Service.connect(Service.java:366)[javax.mail-1.5.5.jar:1.5.5]
        at org.apache.camel.component.mail.MailConsumer.ensureIsConnected(MailConsumer.java:520)[camel-mail-2.18.2.jar:2.18.2]
        at org.apache.camel.component.mail.MailConsumer.poll(MailConsumer.java:94)[camel-mail-2.18.2.jar:2.18.2]
        at org.apache.camel.impl.ScheduledPollConsumer.doRun(ScheduledPollConsumer.java:175)[camel-core-2.18.2.jar:2.18.2]
        at org.apache.camel.impl.ScheduledPollConsumer.run(ScheduledPollConsumer.java:102)[camel-core-2.18.2.jar:2.18.2]
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)[:1.8.0_111]
        at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308)[:1.8.0_111]
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180)[:1.8.0_111]
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294)[:1.8.0_111]
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)[:1.8.0_111]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)[:1.8.0_111]
        at java.lang.Thread.run(Thread.java:745)[:1.8.0_111]

我无法连接到IMAP服务器。

我的代码中是否缺少某些内容?我需要一些SSL配置吗?请注意,我只是在Google邮件设置中启用了IMAP。

我使用maven处理依赖项,使用Eclipse编辑代码。

提前致谢。

0 个答案:

没有答案