【问题标题】:How could I fetch multiple o365 mail details for mail ids using EWS managed API in c#如何在 c# 中使用 EWS 托管 API 获取邮件 ID 的多个 o365 邮件详细信息
【发布时间】:2016-05-10 15:12:40
【问题描述】:

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

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

【问题讨论】:

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


    【解决方案1】:

    试试这个:

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

    【讨论】:

    • 感谢您的宝贵意见,但我需要一次获取某些特定邮件 ID 的邮件详细信息。我认为 service.BindToItems 应该是一个选项。
    • 好的,您如何获得您知道要搜索的邮件 ID?您是否在 EWS 上进行搜索以获取示例中代码之外的内容?我可以使用查询更新我的示例,以获取具体取决于邮件、抄送、发件人等的内容,而不是邮件 ID...
    • 我已经在我的数据库中存储了邮件 ID,并且根据特定标准需要填充一些邮件 ID 详细信息。我使用 service.FindItems() 在我的数据库中查找和存储邮件 ID .
    • 更新了我的答案@GopalBiswas
    • 不用担心,很高兴为您提供帮助!
    猜你喜欢
    • 1970-01-01
    • 2015-03-18
    • 2015-10-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-26
    • 2016-04-05
    相关资源
    最近更新 更多