Aspose.Email EWS - Move to new folder plus IsRead update

I have been struggling to understand how to do the following two operations using Aspose.Email with an EWS client:

  1. Move a message to another folder within the current mailbox.
  2. Update the IsRead flag for the message to indicate that it has been read.

I expected these to be relatively straightforward tasks, but have not been able to find the appropriate documentation to explain how to do it. Can someone please point me to where these tasks are explained?

Thanks,
/jeff haber

@JeffAH,

Thank you for writing to Aspose support team.

We are working on this issue and will write back soon to share our feedback.

@JeffAH,

Thank you for the patience. You may please give a try to the following sample code and share the feedback.

IEWSClient client = EWSClient.GetEWSClient("https://exchange.domain.com/ews/Exchange.asmx", "username", "password", "");
ExchangeMailboxInfo mailboxInfo = client.GetMailboxInfo();
var TempFolder = client.ListSubFolders(mailboxInfo.RootUri).Where(data => data.DisplayName == "Temp").Select(data => data).FirstOrDefault();
// List all messages from Inbox folder
Console.WriteLine("Listing all messages from Inbox....");
ExchangeMessageInfoCollection msgInfoColl = client.ListMessages(mailboxInfo.InboxUri);
foreach (ExchangeMessageInfo msgInfo in msgInfoColl)
{
    client.SetReadFlag(msgInfo.UniqueUri, true);
    client.MoveItem(msgInfo.UniqueUri, TempFolder.Uri); // EWS
}

Thanks for the quick feedback. I’ve successfully tested the part about the IsRead flag, so that is great.

I am working in VB.NET and only slightly familiar with LINQ, so can you please explain the following line in a bit more detail? What is an example of what a value for TempFolder would look like?

Also, is any of your response in the on-line documentation? I would like to be able to find this without having to ‘bother’ you guys.

Thanks.
/jeff

@JeffAH,

The LINQ statement is basically picking names of folders from sub-folders of Mailbox root whose name is “Temp”. It is just like you are traversing the folders of an Exchange Server for searching a particular one. Our documentation contains a full article for working with messages on Exchange server that includes topics related to your query. For example:
Working with Exchange Mailbox and Messages - Read Email from Exchange Server in C#|Documentation is about moving messages between folders. We’ll add an example about setting message flags soon to our documentation.

Thanks for the update. I am finding that sometimes I get an exception which says "Item move failed" but it is not clear from contents of the exception exactly what the code is complaining about. Is there a recommended way of determining the real cause? A stack trace says
“at #=qpRKjSm0n3igTi4B2iAGjTkR01hmo$qOkXO8Eo4_oWuRc$HhFXiB9z$JCRJ$uSAxx.MoveItem(String #=qVIsm0wpS2bh8280TETpUlQ==, String #=qIxmOozBTOZNwEAFXg52L4cxs7hwTv1ZVT0z_hZ4z7zM=)
at test.Form1.Button3_Click(Object sender, EventArgs e)”
but that does not convey any information that looks useful to me.

One other question that is tangentially related to what I am trying to do: Is there any way of going from the MessageID in an Aspose.email.mail.MailMessage to the UniqueUri which is needed for the SetReadFlag and MoveItem methods in your first response? Background: I am trying to port some older code that used Redemption (a competitor of Aspose.Email) to use Aspose.Email because a new version of Exchange broke the version of Redemption we were using but the architecture of our code unfortunately needs to do those two methods in a place where we only have MailMessage, not a ExchangeMessageInfoCollection.

Thanks,
/jeff

@JeffAH,

We haven’t faced any such exception during moving messages from one folder to another. May be adding Exchange Activity Logging can be of help to you in this regard.

Regarding your inquiry about MessageID, we need to discuss this with our Product team for any possible implementation. If EWS itself provides it, we’ll look into it for implementation at our end.

I looked at the link you supplied about Exchange Activity Logging but it is not clear enough for me to try it. Specifically, it says to modify the app.config but does not say which app.config. I tried added those changes to the app.config for the test harness I have been using as well as the app.config associated with the program that I trying to modify but in each case it just gave errors when it tried to instantiate the EWSClient so I really do not have a clear picture of what the document is suggesting. Can you please clarify this?

Thanks,
/jeff

Update: I got the MoveItem to work okay. My translation of your code to get a value for TempFolder was incorrect because of that way I had tried to translate it from C# to VB.NET. The code that I got to work is
destFolderUri = (myEWSClient.ListSubFolders(EMI.RootUri).Where(Function(ff) ff.DisplayName = “Processed”).Select(Function(ff) ff.Uri).SingleOrDefault()).ToString

I am still very interested in the answer to my question about how to map from MessageID to UniqueURI.

Thanks,
/jeff

@JeffAH,

Messages can be listed from Exchange Server using their UniqueURI only. If you need to search for messages with particular MessageID, you can use the ExchangeQueryBuilder for filtering messages on MessageID.

Yes, I knew that but was looking for something a bit more direct. The open question I have about that methodology is that I can see how to do it against the Inbox but what if I did not know where a specific message was located? Is there a different syntax that I am just missing?

Here’s the code that I have been able to get to work:

            Dim bldr As ExchangeQueryBuilder
            Dim emc As ExchangeMessageInfoCollection
            bldr = New ExchangeQueryBuilder()
            bldr.MessageId.Equals(msg.MessageId)
            emc = myEWSClient.ListMessages(myEWSClient.MailboxInfo.**InboxUri**, bldr.GetQuery())
            MsgBox("UniqueUri: " & emc(0).UniqueUri) '<<< this is the value I was trying to find

Thanks,
/jeff

@JeffAH,

I am afraid that no other option is available to retrieve this value. Your code seems to be the right one to fetch this value.

P.S. Please create new thread if you have any other query, as it is helpful for tracking different issues and respective data.