簡體   English   中英

如何使用C#中的EWS托管API獲取多個O365郵件ID的郵件詳細信息

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

我需要使用c#中的EWS托管API來獲取不同郵件ID的多個o365郵件詳細信息。 假設我有1,2,3這樣的o365郵件ID ...

當我將傳遞這些郵件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;
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM