gpt4 book ai didi

java - Pop3MailReciever 不删除邮件

转载 作者:行者123 更新时间:2023-11-30 10:58:16 25 4
gpt4 key购买 nike

我正在使用 Spring Integration 中的 Pop3MailReciever 连接到 POP3 邮件服务器。我想在处理后删除消息。我尝试设置 ShouldDeleteMessages 标志,但它不会删除消息。这是执行轮询的代码:

@SpringBootApplication
public class EmailPollerApplication {

public static void main(String[] args) {
SpringApplication.run(EmailPollerApplication.class, args);
}

@Bean
IntegrationFlow pollingFlow() {
return IntegrationFlows
.from(mailReceivingMessageSource(), e -> e.poller(Pollers.fixedDelay(60000L)))
.transform(mailTransformer())
.transform(requestTransformer())
.handle(wsGateway())
.channel("nullChannel")
.get();
}

@Bean
MailReceivingMessageSource mailReceivingMessageSource(){

Pop3MailReceiver pop3MailReceiver = new Pop3MailReceiver("mailserver.example.com", 110, "username", "password");

pop3MailReceiver.setShouldDeleteMessages(true);
pop3MailReceiver.setMaxFetchSize(1);

MailReceivingMessageSource mailReceivingMessageSource = new MailReceivingMessageSource(pop3MailReceiver);
return mailReceivingMessageSource;
}

这是 Pop3MailReciever 中应该删除邮件的代码:

@Override
protected void deleteMessages(Message[] messages) throws MessagingException {
super.deleteMessages(messages);
// expunge deleted mails, and make sure we've retrieved them before closing the folder
for (int i = 0; i < messages.length; i++) {
new MimeMessage((MimeMessage) messages[i]);
}
}

super.deleteMessages(message) 在消息上设置 DELETED 标志。这一切都很好,但服务器上没有发生任何事情。当我的应用程序正在运行时,我运行了 tcpdump,但 DELE POP3 命令从未运行过。

最佳答案

mail.debug javamail 属性设置为 true 并查看输出。

我刚刚运行了一个没有问题的测试......

DEBUG POP3: connecting to host "localhost", port 52026, isSSL false
+OK POP3
CAPA
+OK
USER
.
DEBUG POP3: server doesn't support TOP, disabling it
DEBUG POP3: authentication command trace suppressed
DEBUG POP3: authentication command succeeded
2015-09-01 08:14:21,913 Pop3MailReceiver [task-scheduler-1] : opening folder [pop3://user:*****@localhost:52026/INBOX]
STAT
+OK 1 3
2015-09-01 08:14:21,914 Pop3MailReceiver [task-scheduler-1] : attempting to receive mail from folder [INBOX]
NOOP
+OK
2015-09-01 08:14:21,927 Pop3MailReceiver [task-scheduler-1] : found 1 new messages
RETR 1
+OK
To: foo@bar
From: bar@baz
Subject: Test Email

foo
.
2015-09-01 08:14:21,930 Pop3MailReceiver [task-scheduler-1] : Received 1 messages
2015-09-01 08:14:21,930 Pop3MailReceiver [task-scheduler-1] : USER flags are not supported by this mail server. Flagging message with system flag
NOOP
+OK
DELE 1
+OK
QUIT
+OK

关于java - Pop3MailReciever 不删除邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32327646/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com