在 Outlook.com 中发送、接收和组织电子邮件
public static String getOAuth2Token() throws MalformedURLException, ExecutionException, InterruptedException { IClientCredential credential = ClientCredentialFactory.createFromSecret(CLIENT_SECRET); ConfidentialClientApplication app = ConfidentialClientApplication .builder(CLIENT_ID, credential) .authority("https://login.microsoftonline.com/" + TENANT_ID) .build();
ClientCredentialParameters parameters = ClientCredentialParameters
.builder(Collections.singleton("https://outlook.office365.com/.default"))
.build();
CompletableFuture<IAuthenticationResult> future = app.acquireToken(parameters);
IAuthenticationResult result = future.get();
return result.accessToken();
}
这样获取的token
然后报错Exception in thread "main" javax.mail.AuthenticationFailedException: 535 5.7.3 Authentication unsuccessful [SG2PR06CA0223.apcprd06.prod.outlook.com 2024-10-14T12:38:13.218Z 08DCEB49AB5D4828]