如何解决我java代码调用microsoft graph api报错

lpz 0 信誉分
2024-03-25T05:48:09.87+00:00

codeUser's image console
User's image

Microsoft 安全 Microsoft Graph
0 个注释 无注释
{count} 票

1 个答案

排序依据: 非常有帮助
  1. CarlZhao-MSFT 46,371 信誉分
    2024-03-25T09:04:29.5266667+00:00

    Hi @lpz

    'text/html' 不是一个有效的 contentType,它应该是一个单独的 'text' 或 'html' 值。

    因此请尝试将您的代码段改为:

    GraphServiceClient graphClient = new GraphServiceClient(requestAdapter);
    
    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<Recipient> toRecipients = new LinkedList<Recipient>();
    Recipient recipient = new Recipient();
    EmailAddress emailAddress = new EmailAddress();
    emailAddress.setAddress("******@contoso.com");
    recipient.setEmailAddress(emailAddress);
    toRecipients.add(recipient);
    message.setToRecipients(toRecipients);
    LinkedList<Recipient> ccRecipients = new LinkedList<Recipient>();
    Recipient recipient1 = new Recipient();
    EmailAddress emailAddress1 = new EmailAddress();
    emailAddress1.setAddress("******@contoso.com");
    recipient1.setEmailAddress(emailAddress1);
    ccRecipients.add(recipient1);
    message.setCcRecipients(ccRecipients);
    sendMailPostRequestBody.setMessage(message);
    sendMailPostRequestBody.setSaveToSentItems(false);
    graphClient.users().byUserId("{user-id}").sendMail().post(sendMailPostRequestBody);
    
    

    User's image


    Hope this helps.

    If the reply is helpful, please click Accept Answer and kindly upvote it. If you have additional questions about this answer, please click Comment.

    Regards.

    Carl


你的答案

问题作者可以将答案标记为“接受的答案”,这有助于用户了解已解决作者问题的答案。