我正在为IMAP空闲事件使用Spring集成邮件。我想使用令牌实现一个IMAP Gmail客户端,而不是使用用户名和密码。
Spring集成邮件IMAP是否能够使用访问令牌连接到Gmail商店?
以下是我使用的代码
IntegrationFlow flow = IntegrationFlows
.from(Mail.imapIdleAdapter("imaps://[username]:[password]@imap.gmail.com:993/inbox")
.javaMailProperties(p -> p
.put("mail.debug", "false")
.autoStartup(false)
.shouldReconnectAutomatically(true)
.userFlag("testSIUserFlag")
.headerMapper(new DefaultMailHeaderMapper()))
.handle((Message<?> message) -> {
logger.info("message: " + message);
})
.get();
2条答案
按热度按时间46scxncf1#
嗯,听起来我们只需要执行一些REST请求来获取令牌,并与一些Java Mail属性一起将其设置到URL中,而不是
[password]
占位符:https://kgiann78.github.io/java/gmail/2017/03/16/JavaMail-send-mail-at-Google-with-XOAUTH2.html为此,听起来您应该使用动态流注册,因此您可以首先执行令牌请求,然后根据第一个请求结果注册
Mail.imapIdleAdapter()
:https://docs.spring.io/spring-integration/docs/current/reference/html/dsl.html#java-dsl-runtime-flows3xiyfsfu2#
这个场景对你有效吗?我已经使用了javaMailAuthenticator,它的身份验证很好,但在刷新令牌时遇到了问题。
即使是这样,这里也有一个悬而未决的问题,-https://stackoverflow.com/questions/73629852/will-integrationflowcontext-remove-destroys-currently-running-integrationflow