如何在c#

时间:2016-05-09 08:24:40

标签: c# exchangewebservices ews-managed-api o365rwsclient

我需要使用c#中的EWS托管API为不同的邮件ID获取多个o365邮件详细信息。假设我有o365邮件ID,如1,2,3 ......

当我传递这些邮件ID并调用EWS托管API时,应填充邮件ID的详细信息。我使用以下代码完成了单个电子邮件ID的详细信息填充:

 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);

如果有人有任何建议请分享。

1 个答案:

答案 0 :(得分: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;
}