locked
how can change a message read status with ews RRS feed

  • Question

  •  

    Hi There,

     

     

    How do I change message status flag from unread to readed?

     

    Thanks in advance,

     

    huafeng

    Thursday, November 27, 2008 3:28 AM

Answers

  • You need to use an UpdateItem operation and set the IsRead property to true eg

     

    Code Snippet

    // Create an object of update item type
    UpdateItemType updateItemType = new UpdateItemType();
    updateItemType.ConflictResolution = ConflictResolutionType.AlwaysOverwrite;
    updateItemType.MessageDisposition = MessageDispositionType.SaveOnly;
    updateItemType.MessageDispositionSpecified = true;
    updateItemType.ItemChanges = new ItemChangeType[1];
    ItemChangeType changeType = new ItemChangeType();

    changeType.Item = message.ItemId;
    changeType.Updates = new ItemChangeDescriptionType[1];

    // Create a set item field to identify the type of update
    SetItemFieldType setItemEmail = new SetItemFieldType();

    PathToUnindexedFieldType epExPath = new PathToUnindexedFieldType();
    epExPath.FieldURI = UnindexedFieldURIType.messageIsRead;

    MessageType mtMessage = new MessageType();
    mtMessage.IsRead = true;
    mtMessage.IsReadSpecified = true;

    setItemEmail.Item = epExPath;
    setItemEmail.Item1 = mtMessage;

    changeType.Updates[0] = setItemEmail;
    updateItemType.ItemChanges[0] = changeType;
    // Send the update item request and receive the response
    UpdateItemResponseType updateItemResponse = esb.UpdateItem(updateItemType);

     

    Cheers

    Glen

     

    • Marked as answer by 刘华锋 Sunday, February 22, 2009 4:42 AM
    Thursday, November 27, 2008 10:02 PM

All replies

  • You need to use an UpdateItem operation and set the IsRead property to true eg

     

    Code Snippet

    // Create an object of update item type
    UpdateItemType updateItemType = new UpdateItemType();
    updateItemType.ConflictResolution = ConflictResolutionType.AlwaysOverwrite;
    updateItemType.MessageDisposition = MessageDispositionType.SaveOnly;
    updateItemType.MessageDispositionSpecified = true;
    updateItemType.ItemChanges = new ItemChangeType[1];
    ItemChangeType changeType = new ItemChangeType();

    changeType.Item = message.ItemId;
    changeType.Updates = new ItemChangeDescriptionType[1];

    // Create a set item field to identify the type of update
    SetItemFieldType setItemEmail = new SetItemFieldType();

    PathToUnindexedFieldType epExPath = new PathToUnindexedFieldType();
    epExPath.FieldURI = UnindexedFieldURIType.messageIsRead;

    MessageType mtMessage = new MessageType();
    mtMessage.IsRead = true;
    mtMessage.IsReadSpecified = true;

    setItemEmail.Item = epExPath;
    setItemEmail.Item1 = mtMessage;

    changeType.Updates[0] = setItemEmail;
    updateItemType.ItemChanges[0] = changeType;
    // Send the update item request and receive the response
    UpdateItemResponseType updateItemResponse = esb.UpdateItem(updateItemType);

     

    Cheers

    Glen

     

    • Marked as answer by 刘华锋 Sunday, February 22, 2009 4:42 AM
    Thursday, November 27, 2008 10:02 PM
  • hi  Glen Scales

     

        if i want to change a message's ToRecipients and CcRecipients and other parts(like subject and so on),how do i write the code like the example above? because i see the code like this when change the message readstatus:

         PathToUnindexedFieldType epExPath = new PathToUnindexedFieldType();
         epExPath.FieldURI = UnindexedFieldURIType.messageIsRead;

     

        that's all,thaks!

       

    Friday, November 28, 2008 1:08 AM
  • Are you trying to do this on a message that is received and already in a users mailbox or on a message that you are sending ? you can't modify the recipients (To,CC,From address)of a message after it has been committed to a mailbox. For the subject and most other properties you use the same method as in my first post but you need to create a separate SetItemFieldType for each change you want to make. I suggest having a read of http://msdn.microsoft.com/en-us/library/cc974151.aspx which gives an example of updating multiple properties with on UpdateItem request. If you can you might want to get a hold of the MSPress book Inside Exchange Web Services which gives a more detailed description of using UpdateItem and EWS in general.

     

    Cheers

    Glen

     

    Friday, November 28, 2008 1:41 AM
  • thank you your reply.

    now my goal is sending a email with attachment.

    when creating attachment with ews,is it must bind to a message? but at that time,the mail may not be complete.

    how i do this?

     i hope that the email with attachment can be sent quickly to the exchange.

     

     thanks.

     

     

    Friday, November 28, 2008 1:49 AM
  • When sending a message with an attachment you need to use three operations you first need to create the message as a draft using a CreateItem operation, then use a CreateAttachment operation to add the attachment then send use a SendItem operation to send the message. You can do it in one operation if you first encoded the message you want to send in MIME and then post the MIME content instead. I posted a sample a while ago of both methods on http://gsexdev.blogspot.com/2007/01/sending-attachments-via-exchange-web.html

     

    Cheers

    Glen

    Friday, November 28, 2008 3:24 AM
  • Does this answer still apply in July 2010, using the EWS Managed API 1.0 with Exchange Server 2007 SP2? Can anything be done with the EmailMessage IsRead property? This answer seems awfully complicated, and there doesn't seem to be much documentation or discussion of it. I'm looping through existing messages in an Inbox, and want to mark each one as IsRead = true as I go (or even once for all of them at the end).

    Thursday, July 8, 2010 7:43 PM
  • The ManagedAPI simplifies this greatly eg its only a few lines of code

              EmailMessage emEmail = EmailMessage.Bind(service, "itemid");
              emEmail.Load();
              emEmail.IsRead = true;
              emEmail.Update(ConflictResolutionMode.AlwaysOverwrite);
    
    Cheers
    Glen
    Friday, July 9, 2010 11:19 PM
  • Thank you, Glen, that seems to be working! (I'm only posting now because I went on vacation the day after I posted my question and am only now gettign back to this issue!)

    How do I indicate here that you answered my question? Is that the "Propose As Answer" button? But that seems like a button you would use, and I should confirm it.

    Monday, September 13, 2010 5:16 PM