我如何在 c# 中使用 EWS managed API 获取邮件 ID 的多个 o365 邮件详细信息

How could I fetch multiple o365 mail details for mail ids using EWS managed API in c#

我需要使用 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);

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

试试这个:

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