简体   繁体   中英

node-ews Update email to mark as read

I'm using "node-ews" library version 3.5.0, but when I try to update any property I get the following error:

{
   "ResponseMessages":{
      "UpdateItemResponseMessage":{
         "attributes":{
            "ResponseClass":"Error"
         },
         "MessageText":"An internal server error occurred. The operation failed., Object reference not set to an instance of an object.",
         "ResponseCode":"ErrorInternalServerError",
         "DescriptiveLinkKey":0,
         "Items":null
      }
   }
}

I'm trying to mark email as read using the following code:

const markFolderAsRead = async (ews, id, changeKey) => {
  const args = {
    attributes: {
      MessageDisposition: "SaveOnly",
    },
    ItemChanges: {
      ItemChange: {
        ItemId: {
          attributes: {
            Id: id,
            ChangeKey: changeKey,
          },
        },
        Updates: {
          SetItemField: {
            FieldURI: {
              attributes: {
                FieldURI: "message:IsRead",
              },
              Message: {
                IsRead: true,
              },
            },
          },
        },
      },
    },
  };
  await ews.run("UpdateItem", args).then((result) => {
    console.log("email read:", JSON.stringify(result));
  });
};

I tried several modifications, including trying to update another fields, but none of it worked. I followed this documentation: https://learn.microsoft.com/pt-br/exchange/client-developer/web-service-reference/updateitem-operation And the lib doesn't show any example of it, but when I change the json to a wrong "soap" construction the error show different messages, or even if I do not pass any of the parameters required as "ChangeKey". So, maybe this error is something relate to microsoft ews soap construction that I'm missing parameters, or so.

Got it working!

My JSON was wrong. The FieldURI was finishing after the message attribute, it should be before.

Correct JSON:

const args = {
    attributes: {
      MessageDisposition: "SaveOnly",
      ConflictResolution: "AlwaysOverwrite",
      SendMeetingInvitationsOrCancellations: "SendToNone",
    },
    ItemChanges: {
      ItemChange: {
        ItemId: {
          attributes: {
            Id: id,
            ChangeKey: changeKey,
          },
        },
        Updates: {
          SetItemField: {
            FieldURI: {
              attributes: {
                FieldURI: "message:IsRead",
              },
            },
            Message: {
              IsRead: "true",
            },
          },
        },
      },
    },
  };

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM