Java 确定[UIDNEXT 2856]下一个唯一标识符值 A27正常[只读]检查已完成。 A28关闭 A28正常关闭完成。 调试IMAPS:添加了经过身份验证的连接--大小:1 2020-06-05 03:06:44.788调试15568---[scheduling-1]o.s.i.mail.MailReceivingMessageSource:收到的邮件[org.springframework.integration.mail.AbstractMailReceiver]$IntegrationMimeMessage@3904c3] 2020-06-05 03:06:44.796调试15568---[scheduling-1]o.s.i.e.SourcePollingChannelAdapter:轮询结果为消息:GenericMessage[payload=org.springframework.integration.mail.AbstractMailReceiver$IntegrationMimeMessage@3904c3,标头={id=7c50d96e-36da-b55f-9862-2215117ef304,时间戳=1591306604796}] 2020-06-05 03:06:44.798调试15568---[scheduling-1]o.s.integration.channel.DirectChannel:在“bean”mailListener.channel#0”频道上显示;在“类路径资源[com//mail/MailPoller.class]”中定义;来自源:“bean方法mailListener”,消息:GenericMessage[payload=org.springframework.integration.mail.AbstractMailReceiver$IntegrationMimeMessage@3904c3,标头={id=7c50d96e-36da-b55f-9862-2215117ef304,时间戳=1591306604796}] 收到一封新邮件 2020-06-05 03:06:44.799调试15568---[scheduling-1]o.s.integration.channel.DirectChannel:channel'bean'mailstener.channel#0'上的postSend(sent=true);在“类路径资源[com/mail/MailPoller.class]”中定义;来自源:“bean方法mailListener”,消息:GenericMessage[payload=org.springframework.integration.mail.AbstractMailReceiver$IntegrationMimeMessage@3904c3,标头={id=7c50d96e-36da-b55f-9862-2215117ef304,时间戳=1591306604796}] 调试IMAPS:IMAPProtocol noop

Java 确定[UIDNEXT 2856]下一个唯一标识符值 A27正常[只读]检查已完成。 A28关闭 A28正常关闭完成。 调试IMAPS:添加了经过身份验证的连接--大小:1 2020-06-05 03:06:44.788调试15568---[scheduling-1]o.s.i.mail.MailReceivingMessageSource:收到的邮件[org.springframework.integration.mail.AbstractMailReceiver]$IntegrationMimeMessage@3904c3] 2020-06-05 03:06:44.796调试15568---[scheduling-1]o.s.i.e.SourcePollingChannelAdapter:轮询结果为消息:GenericMessage[payload=org.springframework.integration.mail.AbstractMailReceiver$IntegrationMimeMessage@3904c3,标头={id=7c50d96e-36da-b55f-9862-2215117ef304,时间戳=1591306604796}] 2020-06-05 03:06:44.798调试15568---[scheduling-1]o.s.integration.channel.DirectChannel:在“bean”mailListener.channel#0”频道上显示;在“类路径资源[com//mail/MailPoller.class]”中定义;来自源:“bean方法mailListener”,消息:GenericMessage[payload=org.springframework.integration.mail.AbstractMailReceiver$IntegrationMimeMessage@3904c3,标头={id=7c50d96e-36da-b55f-9862-2215117ef304,时间戳=1591306604796}] 收到一封新邮件 2020-06-05 03:06:44.799调试15568---[scheduling-1]o.s.integration.channel.DirectChannel:channel'bean'mailstener.channel#0'上的postSend(sent=true);在“类路径资源[com/mail/MailPoller.class]”中定义;来自源:“bean方法mailListener”,消息:GenericMessage[payload=org.springframework.integration.mail.AbstractMailReceiver$IntegrationMimeMessage@3904c3,标头={id=7c50d96e-36da-b55f-9862-2215117ef304,时间戳=1591306604796}] 调试IMAPS:IMAPProtocol noop,java,spring-integration,jakarta-mail,spring-integration-dsl,spring-dsl,Java,Spring Integration,Jakarta Mail,Spring Integration Dsl,Spring Dsl,这是因为接收器。setShouldMarkMessagesRead(true) 如果你把它改成false,我想两者都会得到它;问题是,您必须手动将其标记为“已看到”,以防止下次应用程序启动时重新获取它 您还应该能够使用自定义的SearchTerm策略。默认策略包括 if(supportedFlags.contains(Flags.Flag.SEEN)){ NotTerm notSeen=new NotTerm(new FlagTerm(new Flags(Flags.Flag.SEEN),tru

这是因为
接收器。setShouldMarkMessagesRead(true)

如果你把它改成false,我想两者都会得到它;问题是,您必须手动将其标记为“已看到”,以防止下次应用程序启动时重新获取它

您还应该能够使用自定义的
SearchTerm策略
。默认策略包括

if(supportedFlags.contains(Flags.Flag.SEEN)){
NotTerm notSeen=new NotTerm(new FlagTerm(new Flags(Flags.Flag.SEEN),true));
if(searchTerm==null){
searchTerm=notSeen;
}
否则{
searchTerm=新的AndTerm(searchTerm,不可见);
}
}
使用自定义搜索词,您还应该能够在每个实例中使用不同的
userFlag
;允许每个用户以这种方式将邮件标记为已读(只要IMAP服务器支持
Flag.USER


请参阅
ImapMailReceiver.DefaultSearchTermStrategy
了解默认策略的工作原理。

trusted receiver.setShouldMarkMessagesRead(false);仍然只有一个实例收到新的电子邮件,这意味着
标志。服务器不支持最近的
。在这种情况下,适配器将退回并使用
标志。用户
标记记录(不管布尔值如何)。默认用户标志是
spring integration mail adapter
,这意味着默认搜索策略将忽略它。请尝试在您的一个环境上设置不同的标志值(
setUserFlag
),以查看其是否有效。您可以使用
mail.debug=true
查看所有标志活动(“dev标志”)和receiver.setUserFlag(“stage标志”);对于开发和阶段应用程序,仍然只有一个实例接收电子邮件。将粘贴调试日志,每1分钟打印一次,这没有帮助;我需要查看实际接收和标记消息的日志。您可以编辑邮件本身的内容;我只需要查看IMAP交互,标记电子邮件tc,包括在开头附近的功能请求/回复。对于同一时间段的
org.springframework.integration.mail
调试日志也会很有用。
@Bean
    public IntegrationFlow mailListener() {

        return IntegrationFlows.from(Mail.imapInboundAdapter(receiver()), e -> e.poller(Pollers.fixedRate(60000).maxMessagesPerPoll(-1)))
                .<Message>handle(message -> logMail(message)).get();
    }

    private org.springframework.messaging.Message<?> logMail(org.springframework.messaging.Message<?> message) {
        System.out.println("received a mail********** !");
        // System.out.println(message.getPayload());
        // process message
        return message;
    }

    @Bean
    public ImapMailReceiver receiver() {

        ImapMailReceiver receiver = new ImapMailReceiver(
                "imaps://username:pwd@mail.company.com/INBOX");
        receiver.setShouldMarkMessagesAsRead(true);
        receiver.setJavaMailProperties(javaMailProperties());
        return receiver;
    }

    private Properties javaMailProperties() {
        Properties javaMailProperties = new Properties();

        /*
         * javaMailProperties.setProperty("mail.imap.socketFactory.class",
         * "javax.net.ssl.SSLSocketFactory");
         * javaMailProperties.setProperty("mail.imap.socketFactory.fallback","false");
         * javaMailProperties.setProperty("mail.store.protocol","imaps");
         */
        // javaMailProperties.setProperty("mail.debug","true");

        return javaMailProperties;
    }
DEBUG IMAPS: IMAPProtocol noop
A20 NOOP
A20 OK NOOP completed.
A21 LIST "" INBOX
* LIST (\Marked \HasNoChildren) "/" INBOX
A21 OK LIST completed.
2020-06-05 03:06:39.003 DEBUG 15568 --- [   scheduling-1] o.s.integration.mail.ImapMailReceiver    : opening folder [imaps://user.name%40company.com@mail.ad.company.com/INBOX]
DEBUG IMAPS: connection available -- size: 1
A22 SELECT INBOX
* 1438 EXISTS
* 1 RECENT
* FLAGS (\Seen \Answered \Flagged \Deleted \Draft $MDNSent)
* OK [PERMANENTFLAGS (\Seen \Answered \Flagged \Deleted \Draft $MDNSent)] Permanent flags
* OK [UNSEEN 228] Is the first unseen message
* OK [UIDVALIDITY 2278797] UIDVALIDITY value
* OK [UIDNEXT 2855] The next unique identifier value
A22 OK [READ-WRITE] SELECT completed.
2020-06-05 03:06:39.752  INFO 15568 --- [   scheduling-1] o.s.integration.mail.ImapMailReceiver    : attempting to receive mail from folder [INBOX]
2020-06-05 03:06:39.752 DEBUG 15568 --- [   scheduling-1] o.s.integration.mail.ImapMailReceiver    : This email server does not support RECENT or USER flags. System flag 'Flag.FLAGGED' will be used to prevent duplicates during email fetch.
A23 SEARCH NOT (ANSWERED) NOT (DELETED) NOT (SEEN) NOT (FLAGGED) ALL
* SEARCH 1438
A23 OK SEARCH completed.
2020-06-05 03:06:40.488 DEBUG 15568 --- [   scheduling-1] o.s.integration.mail.ImapMailReceiver    : found 1 new messages
A24 FETCH 1438 (ENVELOPE INTERNALDATE RFC822.SIZE FLAGS BODYSTRUCTURE)
* 1438 FETCH (ENVELOPE ("Thu, 4 Jun 2020 17:36:21 -0400" "test message" (("sender,name (Company)" NIL "Sender.name" "company.com")) NIL NIL (("~receiver name" NIL "user.name" "company.com")) NIL NIL "<KL1P101MB0152E33B47someid@KL1P101MB0152.NAMP101.PROD.OUTLOOK.COM>" "<KL1P101MB0152E33B4someid@KL1P101MB0152.NAMP101.PROD.OUTLOOK.COM>") INTERNALDATE "04-Jun-2020 17:36:28 -0400" RFC822.SIZE 2638 FLAGS (\Recent) BODYSTRUCTURE ("text" "html" ("charset" "us-ascii") NIL NIL "7BIT" 0 0 NIL NIL "en-US" NIL))
A24 OK FETCH completed.
2020-06-05 03:06:41.536 DEBUG 15568 --- [   scheduling-1] o.s.integration.mail.ImapMailReceiver    : Received 1 messages
2020-06-05 03:06:41.536 DEBUG 15568 --- [   scheduling-1] o.s.integration.mail.ImapMailReceiver    : USER flags are not supported by this mail server. Flagging message with system flag
A25 STORE 1438 +FLAGS (\Flagged)
* 1438 FETCH (FLAGS (\Flagged \Recent))
A25 OK STORE completed.
A26 FETCH 1438 (BODY.PEEK[]<0.16384>)
* 1438 FETCH (BODY[]<0> {3198}
Received: from ALPMBHT04.e2k.ad.company.com (3.159.19.197) by
 ALPURAPA30.e2k.ad.company.com (3.159.16.198) with Microsoft SMTP Server (TLS) id
 14.3.487.0; Thu, 4 Jun 2020 17:36:28 -0400
Received: from APC01-HK2-obe.outbound.protection.outlook.com (10.38.143.172)
 by mail.o365.company.com (3.159.19.197) with Microsoft SMTP Server (TLS) id
 14.3.487.0; Thu, 4 Jun 2020 17:36:28 -0400
Received: from KL1P101MB0152.NAMP101.PROD.OUTLOOK.COM (2603:1096:808:3::27) by
 KL1P101MB0151.NAMP101.PROD.OUTLOOK.COM (2603:1096:808:3::26) with Microsoft
 SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id
 15.20.3045.25; Thu, 4 Jun 2020 21:36:21 +0000
Received: from KL1P101MB0152.NAMP101.PROD.OUTLOOK.COM ([129.75.125.219]) by
 KL1P101MB0152.NAMP101.PROD.OUTLOOK.COM ([129.75.125.219]) with mapi id
 15.20.3045.029; Thu, 4 Jun 2020 21:36:21 +0000
From: "sender,name (Company)" <Sender.name@company.com>
To: ~receiver name <user.name@company.com>
Subject: test message
Thread-Topic: test message
Thread-Index: AdY6s3z4MSq0ceMSRqCEtXhoAxXllAABK3Aw
Date: Thu, 4 Jun 2020 17:36:21 -0400
Message-ID:
 <KL1P101MB0152E33B47someid@KL1P101MB0152.NAMP101.PROD.OUTLOOK.COM>
References:
 <KL1P101MB0152E33B47someid@KL1P101MB0152.NAMP101.PROD.OUTLOOK.COM>
In-Reply-To:
 <KL1P101MB0152E33B47someid@KL1P101MB0152.NAMP101.PROD.OUTLOOK.COM>
Accept-Language: en-IN, en-US
Content-Language: en-US
X-MS-Exchange-Organization-AuthAs: Internal
X-MS-Exchange-Organization-AuthMechanism: 04
X-MS-Exchange-Organization-AuthSource: KL1P101MB0152.NAMP101.PROD.OUTLOOK.COM
X-MS-Has-Attach:
X-MS-Exchange-Organization-SCL: -1
X-Message-Flag: Follow up
X-MS-TNEF-Correlator:
Content-Type: text/html; charset="us-ascii"
MIME-Version: 1.0

<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
    {font-family:"Cambria Math";
    panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
    {font-family:Calibri;
    panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
    {margin:0cm;
    margin-bottom:.0001pt;
    font-size:11.0pt;
    font-family:"Calibri",sans-serif;
    mso-fareast-language:EN-US;}
.MsoChpDefault
    {mso-style-type:export-only;
    font-size:10.0pt;}
@page WordSection1
    {size:612.0pt 792.0pt;
    margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
    {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-IN" link="#0563C1" vlink="#954F72">
<div class="WordSection1">
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
<p class="MsoNormal">Test content<o:p></o:p></p>
</div>
</body>
</html>
)
A26 OK FETCH completed.
A27 EXAMINE INBOX
* 1438 EXISTS
* 0 RECENT
* FLAGS (\Seen \Answered \Flagged \Deleted \Draft $MDNSent)
* OK [PERMANENTFLAGS ()] Permanent flags
* OK [UNSEEN 228] Is the first unseen message
* OK [UIDVALIDITY 2278797] UIDVALIDITY value
* OK [UIDNEXT 2856] The next unique identifier value
A27 OK [READ-ONLY] EXAMINE completed.
A28 CLOSE
A28 OK CLOSE completed.
DEBUG IMAPS: added an Authenticated connection -- size: 1
2020-06-05 03:06:44.788 DEBUG 15568 --- [   scheduling-1] o.s.i.mail.MailReceivingMessageSource    : received mail message [org.springframework.integration.mail.AbstractMailReceiver$IntegrationMimeMessage@3904c3]
2020-06-05 03:06:44.796 DEBUG 15568 --- [   scheduling-1] o.s.i.e.SourcePollingChannelAdapter      : Poll resulted in Message: GenericMessage [payload=org.springframework.integration.mail.AbstractMailReceiver$IntegrationMimeMessage@3904c3, headers={id=7c50d96e-36da-b55f-9862-2215117ef304, timestamp=1591306604796}]
2020-06-05 03:06:44.798 DEBUG 15568 --- [   scheduling-1] o.s.integration.channel.DirectChannel    : preSend on channel 'bean 'mailListener.channel#0'; defined in: 'class path resource [com//mail/MailPoller.class]'; from source: 'bean method mailListener'', message: GenericMessage [payload=org.springframework.integration.mail.AbstractMailReceiver$IntegrationMimeMessage@3904c3, headers={id=7c50d96e-36da-b55f-9862-2215117ef304, timestamp=1591306604796}]
got a new mail
2020-06-05 03:06:44.799 DEBUG 15568 --- [   scheduling-1] o.s.integration.channel.DirectChannel    : postSend (sent=true) on channel 'bean 'mailListener.channel#0'; defined in: 'class path resource [com/mail/MailPoller.class]'; from source: 'bean method mailListener'', message: GenericMessage [payload=org.springframework.integration.mail.AbstractMailReceiver$IntegrationMimeMessage@3904c3, headers={id=7c50d96e-36da-b55f-9862-2215117ef304, timestamp=1591306604796}]
DEBUG IMAPS: IMAPProtocol noop