Spring集成邮件IMAP支持OAuth2吗?

bsxbgnwa  于 2022-10-23  发布在  Spring
关注(0)|答案(2)|浏览(162)

我正在为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();
46scxncf

46scxncf1#

嗯,听起来我们只需要执行一些REST请求来获取令牌,并与一些Java Mail属性一起将其设置到URL中,而不是[password]占位符:https://kgiann78.github.io/java/gmail/2017/03/16/JavaMail-send-mail-at-Google-with-XOAUTH2.html

Properties props = new Properties();
 props.put("mail.imap.ssl.enable", "true"); // required for Gmail
 props.put("mail.imap.sasl.enable", "true");
 props.put("mail.imap.sasl.mechanisms", "XOAUTH2");
 props.put("mail.imap.auth.login.disable", "true");
 props.put("mail.imap.auth.plain.disable", "true");

为此,听起来您应该使用动态流注册,因此您可以首先执行令牌请求,然后根据第一个请求结果注册Mail.imapIdleAdapter():https://docs.spring.io/spring-integration/docs/current/reference/html/dsl.html#java-dsl-runtime-flows

3xiyfsfu

3xiyfsfu2#

这个场景对你有效吗?我已经使用了javaMailAuthenticator,它的身份验证很好,但在刷新令牌时遇到了问题。
即使是这样,这里也有一个悬而未决的问题,-https://stackoverflow.com/questions/73629852/will-integrationflowcontext-remove-destroys-currently-running-integrationflow

相关问题