Spring Integration Mail Google IMAP如何设置检查收件箱的频率

时间:2018-10-16 09:41:34

标签: spring spring-boot spring-integration javamail

我的spring-mail-integration afterAuthentication(){ return localStorage.getItem('isLogged', true); } login(){ localStorage.setItem('login', true); } logout(){ localStorage.setItem('login', false); } 工作正常,可以检查我的Google收件箱。
默认情况下,我注意到它每2分钟检查一次我的收件箱。
我忘记了任何设置检查邮件收件箱时间的代码。
现在,我遇到了一个问题,因为有时(很少)我的应用程序无法从收件箱中读取。.
我只是在日志(Spring boot application)中得到它 解决该问题的方法是重新启动tomcat服务器,然后我的应用程序现在可以再次检查我的电子邮件收件箱。

日志(带有日期和时间):

attempting to receive mail from folder [INBOX]

问题:
1.如何更改检查收件箱的时间?
2.两(2)分钟或更短的时间是一个坏主意吗?我认为Google可能会禁止ip访问/检查收件箱。

依赖性:

2018-10-16 12:37:13 - attempting to receive mail from folder [INBOX]
2018-10-16 12:39:18 - attempting to receive mail from folder [INBOX]
2018-10-16 12:41:22 - attempting to receive mail from folder [INBOX]
2018-10-16 12:43:26 - attempting to receive mail from folder [INBOX]
2018-10-16 12:45:30 - attempting to receive mail from folder [INBOX]
2018-10-16 12:47:35 - attempting to receive mail from folder [INBOX]
2018-10-16 12:49:39 - attempting to receive mail from folder [INBOX]
2018-10-16 12:51:43 - attempting to receive mail from folder [INBOX]
2018-10-16 12:53:47 - attempting to receive mail from folder [INBOX]
2018-10-16 12:55:52 - attempting to receive mail from folder [INBOX]
2018-10-16 12:57:56 - attempting to receive mail from folder [INBOX]
2018-10-16 13:00:00 - attempting to receive mail from folder [INBOX]
2018-10-16 13:02:04 - attempting to receive mail from folder [INBOX]
2018-10-16 13:04:09 - attempting to receive mail from folder [INBOX]
2018-10-16 13:06:13 - attempting to receive mail from folder [INBOX]
2018-10-16 13:08:17 - attempting to receive mail from folder [INBOX]
2018-10-16 13:10:21 - attempting to receive mail from folder [INBOX]
2018-10-16 13:12:25 - attempting to receive mail from folder [INBOX]
2018-10-16 13:14:29 - attempting to receive mail from folder [INBOX]
2018-10-16 13:16:33 - attempting to receive mail from folder [INBOX]
2018-10-16 13:18:37 - attempting to receive mail from folder [INBOX]
2018-10-16 13:20:41 - attempting to receive mail from folder [INBOX]
2018-10-16 13:22:44 - attempting to receive mail from folder [INBOX]
2018-10-16 13:24:48 - attempting to receive mail from folder [INBOX]
2018-10-16 13:26:53 - attempting to receive mail from folder [INBOX]
2018-10-16 13:28:57 - attempting to receive mail from folder [INBOX]
2018-10-16 13:31:02 - attempting to receive mail from folder [INBOX]
2018-10-16 13:33:06 - attempting to receive mail from folder [INBOX]
2018-10-16 13:35:10 - attempting to receive mail from folder [INBOX]
2018-10-16 13:37:14 - attempting to receive mail from folder [INBOX]
2018-10-16 13:39:17 - attempting to receive mail from folder [INBOX]
2018-10-16 13:41:21 - attempting to receive mail from folder [INBOX]
2018-10-16 13:43:25 - attempting to receive mail from folder [INBOX]
2018-10-16 13:45:30 - attempting to receive mail from folder [INBOX]
2018-10-16 13:47:33 - attempting to receive mail from folder [INBOX]
2018-10-16 13:49:38 - attempting to receive mail from folder [INBOX]

邮件配置:

<dependency>
  <groupId>org.springframework.integration</groupId>
  <artifactId>spring-integration-mail</artifactId>
</dependency>

如果您可以提供有关说明的链接,那也很好。

谢谢!

1 个答案:

答案 0 :(得分:1)

设置cancelIdleInterval

/**
 * IDLE commands will be terminated after this interval; useful in cases where a connection
 * might be silently dropped. A new IDLE will usually immediately be processed. Specified
 * in seconds; default 120 (2 minutes). RFC 2177 recommends an interval no larger than 29 minutes.
 * @param cancelIdleInterval the cancelIdleInterval to set
 * @since 3.0.5
 */
public void setCancelIdleInterval(long cancelIdleInterval) {
    this.cancelIdleInterval = cancelIdleInterval * 1000;
}

Java DSL当前未公开它,因此您必须将ImapMailReceiver连接为bean。

编辑

@Bean
public ImapMailReceiver receiver() {
    ImapMailReceiver receiver = new ImapMailReceiver("...some URL...");
    receiver.setCancelIdleInterval(300); // seconds
    receiver.setJavaMailProperties(javaMailProperties);
    return receiver;

}

@Bean
public IntegrationFlow mailFlow() {
    return IntegrationFlows.from(Mail.imapIdleAdapter(receiver()))
            // ...
            .get();
}