81.2. Microsoft Exchange Online OAuth2 Mail Authenticator IMAP 示例
要使用 OAuth,应用程序必须使用 Azure Active Directory 注册。按照说明注册新应用程序。
流程
- 使应用程序能够通过客户端凭证流访问 Exchange 邮箱。如需更多信息,请参阅使用 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")