Reputation: 475
I want to access emails in a folder called "ITServiceDesk" in my exchange inbox.
I can access the folder but i cant figure out how to read the mail inside that folder.
I am accessing the folder here:
var view = new FolderView(100);
view.Traversal = FolderTraversal.Deep;
var fileview = new ItemView(100);
var filter = new SearchFilter.IsEqualTo(FolderSchema.DisplayName, "ITServiceDesk");
// Read 100 mails
foreach (var item in _service.FindFolders(WellKnownFolderName.Inbox, filter, view))
{
MessageBox.Show(item.DisplayName);
foreach (EmailMessage email in _service.FindItems(WellKnownFolderName.Inbox, filter, fileview))
{
email.Load(new PropertySet(EmailMessageSchema.ConversationTopic, ItemSchema.Attachments,
ItemSchema.TextBody));
MessageBox.Show(email.ConversationTopic);
MessageBox.Show(email.TextBody);
}
}
Nothing happens when i get inside the second foreach loop. The message box shows that it can find the folder as the item.displayname is correct.
Upvotes: 2
Views: 3772
Reputation: 22032
If you are finding the folder with you code then just call the findItem method on the Folder object that is returned eg
foreach (var Folder in _service.FindFolders(WellKnownFolderName.Inbox, filter, view))
{
MessageBox.Show(Folder.DisplayName);
foreach (EmailMessage email in Folder.FindItems(fileview))
{
email.Load(new PropertySet(EmailMessageSchema.ConversationTopic, ItemSchema.Attachments,
ItemSchema.TextBody));
MessageBox.Show(email.ConversationTopic);
MessageBox.Show(email.TextBody);
}
}
Upvotes: 2
Reputation: 31721
Here is an example from my website:
FindItemsResults<Item> findResults
= service.FindItems(WellKnownFolderName.Inbox, new ItemView( 10 ) );
foreach ( Item item in findResults.Items )
Console.WriteLine( item.Subject );
See C#: Getting All Emails From Exchange using Exchange Web Services
Upvotes: 0