0

I need to fetch multiple o365 mail details for different mail ids using EWS managed API in c#. Suppose I have o365 mail ids like 1,2,3...

When I will pass these mail ids and call EWS managed API then the details for mail ids should populated. I have done the details population for a single email id using the code like below:

 ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2013_SP1);
            service.Credentials = new WebCredentials("username", "Password");
            service.AutodiscoverUrl(Ownerusername, RedirectionUrlValidationCallback);
            EmailMessage mail = EmailMessage.Bind(service, mailID, PropertySet.FirstClassProperties);

If anybody has any suggestion please share.

4

1 回答 1

0

尝试这个:

ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2013_SP1);
service.Credentials = new WebCredentials("username", "Password");
service.AutodiscoverUrl(Ownerusername, RedirectionUrlValidationCallback);

//Make sure you include the properties you are looking for in EmailMessageSchema
PropertySet propSet = new PropertySet(BasePropertySet.IdOnly, EmailMessageSchema.Subject, EmailMessageSchema.ToRecipients);

//Add your Ids stored in the database here
var itemIds = new List<ItemId>();
foreach(var MailIds in db.Mails.select(a=>a.Ids))
{
    itemIds.add(new ItemId(MailIds));
}

//Send one request to EWS and get all mails by Id
ServiceResponseCollection<GetItemResponse> response = service.BindToItems(itemIds, propSet);

//Get the emails
foreach (GetItemResponse getItemResponse in response)
{
    Item item = getItemResponse.Item;
    EmailMessage message = (EmailMessage)item;
}
于 2016-05-09T10:48:10.307 回答