英文:
"Folder in read-only mode" exception
问题
我正在尝试运行Mail imapInboundAdapter的示例代码,并遇到以下异常:
2020-01-06 19:12:44.584 INFO 5388 --- [ scheduling-1] o.s.integration.mail.ImapMailReceiver : attempting to receive mail from folder [INBOX]
2020-01-06 19:12:44.985 ERROR 5388 --- [ scheduling-1] o.s.integration.handler.LoggingHandler : org.springframework.messaging.MessagingException: failure occurred while polling for mail; nested exception is javax.mail.MessagingException: A7 NO [CLIENTBUG] Folder in read-only mode;
nested exception is:
com.sun.mail.iap.CommandFailedException: A7 NO [CLIENTBUG] Folder in read-only mode
...
这可能的原因是邮箱文件夹处于只读模式。如果要解决此问题,您可以尝试以下步骤:
-
检查邮箱设置:确保您的邮箱设置允许通过IMAP协议进行读取。有些邮箱提供商可能需要您启用IMAP访问。请检查您的邮箱提供商的设置以确保已启用IMAP。
-
验证用户名和密码:确保您在连接字符串中提供的邮箱用户名和密码是正确的,以便可以成功连接到邮箱。
-
邮箱权限:检查您的邮箱文件夹权限,确保您有足够的权限来读取该文件夹中的邮件。有时候,只读文件夹可能会导致无法设置邮件的标志。
-
使用SSL连接:您的示例代码中已经使用了IMAPS协议,这意味着它使用了安全的SSL连接。确保您的邮箱服务器支持IMAPS,并且SSL设置正确。
另外,您提到在收到新邮件时出现了NullPointerException异常。这可能与收到的邮件的内容或格式有关。确保您的代码可以处理各种邮件格式和内容。
最后,您提到您的Maven依赖是spring-boot-starter-parent 2.2.2.RELEASE和javax.mail mail 1.4.7。这些依赖看起来应该是适用的,但请确保它们没有与其他依赖项产生冲突,并且您的项目配置正确。如果有必要,您可以查看最新的Spring Boot和javax.mail版本以获取更新的稳定版本。
希望这些提示可以帮助您解决问题。
英文:
I'm trying to run an example of Mail imapInboundAdapter:
@Bean
public IntegrationFlow mailListener() {
return IntegrationFlows.from(Mail.imapInboundAdapter(
"imaps://myemailt%40mail.ru:mypassword@imap.mail.ru:993/inbox"
)
.javaMailProperties(p -> {
p.put("mail.debug", "false");
p.put("mail.auth", "true");
p.put("mail.imaps.ssl.trust", "*");
})
.get(),
e -> e.poller(Pollers.fixedRate(5000).maxMessagesPerPoll(1)))
.<Message>handle((payload, header) -> payload)
.log()
.get();
}
and getting the following exception:
2020-01-06 19:12:44.584 INFO 5388 --- [ scheduling-1] o.s.integration.mail.ImapMailReceiver : attempting to receive mail from folder [INBOX]
2020-01-06 19:12:44.985 ERROR 5388 --- [ scheduling-1] o.s.integration.handler.LoggingHandler : org.springframework.messaging.MessagingException: failure occurred while polling for mail; nested exception is javax.mail.MessagingException: A7 NO [CLIENTBUG] Folder in read-only mode;
nested exception is:
com.sun.mail.iap.CommandFailedException: A7 NO [CLIENTBUG] Folder in read-only mode
at org.springframework.integration.mail.MailReceivingMessageSource.doReceive(MailReceivingMessageSource.java:74)
at org.springframework.integration.endpoint.AbstractMessageSource.receive(AbstractMessageSource.java:167)
at org.springframework.integration.endpoint.SourcePollingChannelAdapter.receiveMessage(SourcePollingChannelAdapter.java:250)
at org.springframework.integration.endpoint.AbstractPollingEndpoint.doPoll(AbstractPollingEndpoint.java:359)
at org.springframework.integration.endpoint.AbstractPollingEndpoint.pollForMessage(AbstractPollingEndpoint.java:328)
at org.springframework.integration.endpoint.AbstractPollingEndpoint.lambda$null$1(AbstractPollingEndpoint.java:275)
at org.springframework.integration.util.ErrorHandlingTaskExecutor.lambda$execute$0(ErrorHandlingTaskExecutor.java:57)
at org.springframework.core.task.SyncTaskExecutor.execute(SyncTaskExecutor.java:50)
at org.springframework.integration.util.ErrorHandlingTaskExecutor.execute(ErrorHandlingTaskExecutor.java:55)
at org.springframework.integration.endpoint.AbstractPollingEndpoint.lambda$createPoller$2(AbstractPollingEndpoint.java:272)
at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:54)
at org.springframework.scheduling.concurrent.ReschedulingRunnable.run(ReschedulingRunnable.java:93)
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:304)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: javax.mail.MessagingException: A7 NO [CLIENTBUG] Folder in read-only mode;
nested exception is:
com.sun.mail.iap.CommandFailedException: A7 NO [CLIENTBUG] Folder in read-only mode
at com.sun.mail.imap.IMAPMessage.setFlags(IMAPMessage.java:921)
at javax.mail.Message.setFlag(Message.java:578)
at org.springframework.integration.mail.AbstractMailReceiver.setMessageFlags(AbstractMailReceiver.java:538)
at org.springframework.integration.mail.AbstractMailReceiver.postProcessFilteredMessages(AbstractMailReceiver.java:502)
at org.springframework.integration.mail.AbstractMailReceiver.searchAndFilterMessages(AbstractMailReceiver.java:426)
at org.springframework.integration.mail.AbstractMailReceiver.receive(AbstractMailReceiver.java:378)
at org.springframework.integration.mail.MailReceivingMessageSource.doReceive(MailReceivingMessageSource.java:60)
... 17 more
Caused by: com.sun.mail.iap.CommandFailedException: A7 NO [CLIENTBUG] Folder in read-only mode
at com.sun.mail.iap.Protocol.handleResult(Protocol.java:351)
at com.sun.mail.imap.protocol.IMAPProtocol.storeFlags(IMAPProtocol.java:1603)
at com.sun.mail.imap.protocol.IMAPProtocol.storeFlags(IMAPProtocol.java:1588)
at com.sun.mail.imap.IMAPMessage.setFlags(IMAPMessage.java:917)
... 23 more
What can be the reason?
Edit 2. When the email really comes, now I'm getting the new NullPointerException:
2020-01-06 21:09:12.515 INFO 996 --- [ scheduling-1] o.s.integration.mail.ImapMailReceiver : attempting to receive mail from folder [INBOX]
2020-01-06 21:09:17.522 INFO 996 --- [ scheduling-1] o.s.integration.mail.ImapMailReceiver : attempting to receive mail from folder [INBOX]
2020-01-06 21:09:18.328 ERROR 996 --- [ scheduling-1] o.s.integration.handler.LoggingHandler : org.springframework.messaging.MessagingException: failure occurred while polling for mail; nested exception is java.lang.NullPointerException
at org.springframework.integration.mail.MailReceivingMessageSource.doReceive(MailReceivingMessageSource.java:74)
at org.springframework.integration.endpoint.AbstractMessageSource.receive(AbstractMessageSource.java:167)
at org.springframework.integration.endpoint.SourcePollingChannelAdapter.receiveMessage(SourcePollingChannelAdapter.java:250)
at org.springframework.integration.endpoint.AbstractPollingEndpoint.doPoll(AbstractPollingEndpoint.java:359)
at org.springframework.integration.endpoint.AbstractPollingEndpoint.pollForMessage(AbstractPollingEndpoint.java:328)
at org.springframework.integration.endpoint.AbstractPollingEndpoint.lambda$null$1(AbstractPollingEndpoint.java:275)
at org.springframework.integration.util.ErrorHandlingTaskExecutor.lambda$execute$0(ErrorHandlingTaskExecutor.java:57)
at org.springframework.core.task.SyncTaskExecutor.execute(SyncTaskExecutor.java:50)
at org.springframework.integration.util.ErrorHandlingTaskExecutor.execute(ErrorHandlingTaskExecutor.java:55)
at org.springframework.integration.endpoint.AbstractPollingEndpoint.lambda$createPoller$2(AbstractPollingEndpoint.java:272)
at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:54)
at org.springframework.scheduling.concurrent.ReschedulingRunnable.run(ReschedulingRunnable.java:93)
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:304)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: java.lang.NullPointerException
at javax.mail.internet.MimeUtility.quote(MimeUtility.java:975)
at javax.mail.internet.ParameterList.quote(ParameterList.java:672)
at javax.mail.internet.ParameterList.access$200(ParameterList.java:76)
at javax.mail.internet.ParameterList$ToStringBuffer.addNV(ParameterList.java:640)
at javax.mail.internet.ParameterList.toString(ParameterList.java:621)
at javax.mail.internet.ContentType.toString(ContentType.java:221)
at com.sun.mail.imap.IMAPMessage.getDataHandler(IMAPMessage.java:644)
at javax.mail.internet.MimeMessage.getContent(MimeMessage.java:1420)
at org.springframework.integration.mail.AbstractMailReceiver$IntegrationMimeMessage.<init>(AbstractMailReceiver.java:661)
at org.springframework.integration.mail.AbstractMailReceiver.postProcessFilteredMessages(AbstractMailReceiver.java:510)
at org.springframework.integration.mail.AbstractMailReceiver.searchAndFilterMessages(AbstractMailReceiver.java:426)
at org.springframework.integration.mail.AbstractMailReceiver.receive(AbstractMailReceiver.java:378)
at org.springframework.integration.mail.MailReceivingMessageSource.doReceive(MailReceivingMessageSource.java:60)
... 17 more
P.S.
Maven dependencies:
spring-boot-starter-parent 2.2.2.RELEASE
group javax.mail artifact mail version 1.4.7
答案1
得分: 1
请删除适配器规范中的.get()
。
public IntegrationFlow mailListener() {
return IntegrationFlows.from(Mail.imapInboundAdapter(
"imaps://myemailt%40mail.ru:mypassword@imap.mail.ru:993/inbox"
)
.javaMailProperties(p -> {
p.put("mail.debug", "false");
p.put("mail.auth", "true");
p.put("mail.imaps.ssl.trust", "*");
}),
e -> e.poller(Pollers.fixedRate(5000).maxMessagesPerPoll(1)))
.<Message>handle((payload, header) -> payload)
.log();
}
在此使用get()
会阻止框架初始化适配器 bean(从只读切换到读/写模式)。
当注入原始适配器规范时,框架将完成初始化。
英文:
Remove the .get()
from the adapter spec
public IntegrationFlow mailListener() {
return IntegrationFlows.from(Mail.imapInboundAdapter(
"imaps://myemailt%40mail.ru:mypassword@imap.mail.ru:993/inbox"
)
.javaMailProperties(p -> {
p.put("mail.debug", "false");
p.put("mail.auth", "true");
p.put("mail.imaps.ssl.trust", "*");
}),
e -> e.poller(Pollers.fixedRate(5000).maxMessagesPerPoll(1)))
.<Message>handle((payload, header) -> payload)
.log()
.get();
}
Using get()
there prevents the framework from initializing the adapter bean (which switches the mode from read only to read/write).
When the raw adapter spec is injected, the framework will complete the initialization.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论