Когда я проверял наличие ошибок такого типа, я обнаружил, что требуется лицензия M365. Могу ли я пройти аутентификацию без лицензии M365?
Java — ODataError «Почтовый ящик неактивен, обратимо удален или размещен локально».
Вот код
Код: Выделить всё
public class MicrosoftGraphApiSendMailTest {
/**
* send
*/
@Test
public void sendMail() {
try {
final String clientId = "*****";
final String tenantId = "*****";
final String clientSecret = "*****";
final String[] scopes = new String[]{"https://graph.microsoft.com/.default"};
final ClientSecretCredential credential = new ClientSecretCredentialBuilder()
.clientId(clientId).tenantId(tenantId).clientSecret(clientSecret).build();
if (null == scopes || null == credential) {
throw new Exception("Unexpected error");
}
final GraphServiceClient graphClient = new GraphServiceClient(credential, scopes);
// Code snippets are only available for the latest version. Current version is 6.x
com.microsoft.graph.users.item.sendmail.SendMailPostRequestBody sendMailPostRequestBody = new com.microsoft.graph.users.item.sendmail.SendMailPostRequestBody();
Message message = new Message();
message.setSubject("Meet for lunch?");
ItemBody body = new ItemBody();
body.setContentType(BodyType.Text);
body.setContent("The new cafeteria is open.");
message.setBody(body);
LinkedList toRecipients = new LinkedList();
Recipient recipient = new Recipient();
EmailAddress emailAddress = new EmailAddress();
emailAddress.setAddress("*****");
recipient.setEmailAddress(emailAddress);
toRecipients.add(recipient);
message.setToRecipients(toRecipients);
LinkedList ccRecipients = new LinkedList();
Recipient recipient1 = new Recipient();
EmailAddress emailAddress1 = new EmailAddress();
emailAddress1.setAddress("*****");
recipient1.setEmailAddress(emailAddress1);
ccRecipients.add(recipient1);
message.setCcRecipients(ccRecipients);
sendMailPostRequestBody.setMessage(message);
sendMailPostRequestBody.setSaveToSentItems(false);
graphClient.users().byUserId("*****").sendMail().post(sendMailPostRequestBody);
graphClient.me().sendMail().post(sendMailPostRequestBody);
} catch (ApiException e) {
System.out.println(e.getResponseStatusCode());
e.printStackTrace();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
Мне нужно выполнить неинтерактивную аутентификацию, большое спасибо брату, который готов предоставить код!
Подробнее здесь: https://stackoverflow.com/questions/792 ... rror-the-m