我使用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命令从未运行过。
答案 0 :(得分:1)
将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