在草稿状态Microsoft Graph API Java中发布消息创建消息

时间:2020-01-16 09:20:22

标签: java microsoft-graph-api

当我尝试使用Microsoft Graph Java API发送消息时,其状态为草稿。

Authentication.initialize(appId);
    final String accessToken = Authentication.getUserAccessToken(appScopes);

    authProvider = new SimpleAuthProvider(accessToken);

    // Create default logger to only log errors
    DefaultLogger logger = new DefaultLogger();
    logger.setLoggingLevel(LoggerLevel.DEBUG);

    // Build a Graph client
    graphClient = GraphServiceClient.builder()
        .authenticationProvider(authProvider)
        .logger(logger)
        .buildClient();

    IMailFolderDeltaCollectionPage mailFolderCollectionPage = graphClient.me().mailFolders().delta()
        .buildRequest().get();
    AtomicReference<String> inBoxFolderId = new AtomicReference<>("");
    while (mailFolderCollectionPage.getNextPage() != null) {
      List<MailFolder> mailFolders = mailFolderCollectionPage.getCurrentPage();
      mailFolders.forEach(m -> {
        if (m.displayName.equals("Inbox")) {
          inBoxFolderId.set(m.id);
        }
          });

      mailFolderCollectionPage = mailFolderCollectionPage.getNextPage().buildRequest().get();
    }

    IMessageDeltaCollectionPage messageCollectionPage = graphClient.me().mailFolders("Inbox")
        .messages().delta().buildRequest().get();

    Message backedMessaged = null;

    while (messageCollectionPage.getNextPage() != null) {
      System.out.println("messageCollectionPage = " + messageCollectionPage);
      List<Message> messageList = messageCollectionPage.getCurrentPage();
      backedMessaged = messageList.get(0);
      break;
    }

   graphClient.me().mailFolders("Inbox").messages().buildRequest().post(backedMessaged);

1 个答案:

答案 0 :(得分:0)

创建Outlook消息时,其状态将一直保留为草稿,直到发送为止。您应该使用send请求发送消息。然后它将不再标记为草稿。

查看更多信息:https://docs.microsoft.com/fr-fr/graph/api/message-send?view=graph-rest-1.0&tabs=http