第 39 章 Microsoft Oauth 的邮件
从 Camel 3.18.4 开始。
邮件 Microsoft OAuth2 提供了 org.apache.camel.component.mail.MailAuthenticator 的实现,以验证 IMAP/POP/SMTP 连接,并通过 Spring 邮件支持和底层 JavaMail 系统访问电子邮件。
将以下依赖项添加到此组件的 pom.xml 中:
导入 camel-mail-microsoft-oauth 将自动导入 camel-mail 组件。
39.1. Microsoft Exchange Online OAuth2 邮件验证器 IMAP 示例 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
要使用 OAuth,必须在 Azure Active Directory 中注册一个应用程序。按照说明注册新应用程序。
流程
- 使应用程序能够通过客户端凭据流访问交换通信。如需更多信息,请参阅使用 OAuth 验证 IMAP、POP 或 SMTP 连接
-
设置所有内容后,在 registry 中声明并注册,一个
org.apache.camel.component.mail.MicrosoftExchangeOnlineOAuth2MailAuthenticator的实例。 - 例如,在 Spring Boot 应用程序中:
@BindToRegistry("auth")
public MicrosoftExchangeOnlineOAuth2MailAuthenticator exchangeAuthenticator(){
return new MicrosoftExchangeOnlineOAuth2MailAuthenticator(tenantId, clientId, clientSecret, "jon@doe.com");
}
@BindToRegistry("auth")
public MicrosoftExchangeOnlineOAuth2MailAuthenticator exchangeAuthenticator(){
return new MicrosoftExchangeOnlineOAuth2MailAuthenticator(tenantId, clientId, clientSecret, "jon@doe.com");
}
- 然后,在 Camel URI 中引用它,如下所示:
from("imaps://outlook.office365.com:993"
+ "?authenticator=#auth"
+ "&mail.imaps.auth.mechanisms=XOAUTH2"
+ "&debugMode=true"
+ "&delete=false")
from("imaps://outlook.office365.com:993"
+ "?authenticator=#auth"
+ "&mail.imaps.auth.mechanisms=XOAUTH2"
+ "&debugMode=true"
+ "&delete=false")