简体   繁体   中英

How do I search a specific mailbox with Microsoft Exchange WebServices?

I have my own mailbox (email-1) and everyone in my workgroup has access to mailbox (email-2). I need to search for emails in email-2, but it's returning emails from email-1.

using Microsoft.Exchange.WebServices.Data;

service = new ExchangeService(ExchangeVersion.Exchange2013_SP1)
{
    UseDefaultCredentials = true,
    Url = new Uri("https://fake.com/ews/Exchange.asmx")
};

mailbox = new Mailbox("email-2@fake.com");

ItemView view = new ItemView(50)
{
    PropertySet = new PropertySet(BasePropertySet.IdOnly)
};
view.PropertySet.Add(ItemSchema.Subject);

FindItemsResults<Item> items = service.FindItems(WellKnownFolderName.Inbox, "searched value", view);

It's only returning emails from email-1 but none from email-2. I need it to only return emails from email-2.

I haven't found any way to specify the mailbox to search in the FindItems function. Maybe I'm missing something?

can you please try with

service.FindItems(WellKnownFolderName.Inbox, mailbox.ToString(), view);

I had the same problem previously and i can't find that code now to verify. I derived the answer from this blog. https://blog.kloud.com.au/2016/04/19/programmatically-read-email-from-an-exchange-sever-mailbox

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