Spring Boot集成邮件-授权失败错误

时间:2018-06-22 14:05:16

标签: spring-integration javamail spring-dsl

以下是我的用于pop3连接的spring配置bean,

    @Bean
    public IntegrationFlow mailListener() {
        return IntegrationFlows.from(Mail.pop3InboundAdapter("pop3://sample.test:Sample2test_1@xxx.xx.x.xx/INBOX")
                 .shouldDeleteMessages(true).get(), 
                 e -> e.poller(Pollers.fixedRate(5000).maxMessagesPerPoll(1)))
            .<Message>handle((payload, header) -> logMail(payload))
            .get();
    }

还仔细检查了看起来不错的凭据。 得到以下异常,

  

2018-06-22 19:27:54.351错误2092 --- [询问调度程序2]   o.s.integration.handler.LoggingHandler:   org.springframework.messaging.MessagingException:发生故障   在轮询邮件时;嵌套异常为   javax.mail.AuthenticationFailedException:授权在处失败   org.springframework.integration.mail.MailReceivingMessageSource.receive(MailReceivingMessageSource.java:131)     在   org.springframework.integration.endpoint.SourcePollingChannelAdapter.receiveMessage(SourcePollingChannelAdapter.java:224)     在   org.springframework.integration.endpoint.AbstractPollingEndpoint.doPoll(AbstractPollingEndpoint.java:245)     在   org.springframework.integration.endpoint.AbstractPollingEndpoint.access $ 000(AbstractPollingEndpoint.java:58)     在   org.springframework.integration.endpoint.AbstractPollingEndpoint $ 1.call(AbstractPollingEndpoint.java:190)     在   org.springframework.integration.endpoint.AbstractPollingEndpoint $ 1.call(AbstractPollingEndpoint.java:186)     在   org.springframework.integration.endpoint.AbstractPollingEndpoint $ Poller $ 1.run(AbstractPollingEndpoint.java:353)     在   org.springframework.integration.util.ErrorHandlingTaskExecutor $ 1.run(ErrorHandlingTaskExecutor.java:55)     在   org.springframework.core.task.SyncTaskExecutor.execute(SyncTaskExecutor.java:50)     在   org.springframework.integration.util.ErrorHandlingTaskExecutor.execute(ErrorHandlingTaskExecutor.java:51)     在   org.springframework.integration.endpoint.AbstractPollingEndpoint $ Poller.run(AbstractPollingEndpoint.java:344)     在   org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:54)     在   org.springframework.scheduling.concurrent.ReschedulingRunnable.run(ReschedulingRunnable.java:81)     在java.util.concurrent.Executors $ RunnableAdapter.call(未知   源)位于java.util.concurrent.FutureTask.run(未知源)位于   java.util.concurrent.ScheduledThreadPoolExecutor $ ScheduledFutureTask.access $ 201(未知   来源)   java.util.concurrent.ScheduledThreadPoolExecutor $ ScheduledFutureTask.run(未知   源)在java.util.concurrent.ThreadPoolExecutor.runWorker(未知   源),位于java.util.concurrent.ThreadPoolExecutor $ Worker.run(未知   源:java.lang.Thread.run(未知源),由以下原因引起:   javax.mail.AuthenticationFailedException:授权在处失败   com.sun.mail.pop3.POP3Store.protocolConnect(POP3Store.java:208)位于   javax.mail.Service.connect(Service.java:295)在   javax.mail.Service.connect(Service.java:176)在   javax.mail.Service.connect(Service.java:125)在   org.springframework.integration.mail.AbstractMailReceiver.connectStoreIfNecessary(AbstractMailReceiver.java:286)     在   org.springframework.integration.mail.AbstractMailReceiver.openFolder(AbstractMailReceiver.java:293)     在   org.springframework.integration.mail.AbstractMailReceiver.receive(AbstractMailReceiver.java:319)     在   org.springframework.integration.mail.MailReceivingMessageSource.receive(MailReceivingMessageSource.java:112)     ...还有19个

1 个答案:

答案 0 :(得分:0)

有这样一个选项:

/**
 * The Java Mail properties.
 * @param javaMailProperties the javaMailProperties.
 * @return the spec.
 * @see AbstractMailReceiver#setJavaMailProperties(Properties)
 */
public S javaMailProperties(Properties javaMailProperties) {

您可以在此处mail.debug = true进行指定,以跟踪交互过程中邮件协议的状况。

更新

我们在您的日志中有此记录

DEBUG POP3: connecting to host "172.16.1.45", port 995, isSSL false
19:54:46.746 [task-scheduler-1] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Returning cached instance of singleton bean 'errorChannel'
19:54:46.753 [task-scheduler-1] DEBUG org.springframework.integration.channel.PublishSubscribeChannel - preSend on channel 'errorChannel', message: ErrorMessage [payload=org.springframework.messaging.MessagingException: failure occurred while polling for mail; nested exception is javax.mail.MessagingException: Connect failed;
  nested exception is:
    java.net.ConnectException: Connection refused: connect, headers={id=290f4c5a-2dfe-d7cb-0637-a0e9f0394daa, timestamp=1529677486753}]

因此,它不能仅连接到172.16.1.45:995。还没有身份验证握手。