作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 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/
我是一名优秀的程序员,十分优秀!