简体   繁体   English

EWS托管的Api-从Office365交换服务器中检索电子邮件

[英]EWS Managed Api - Retrieving e-mails from Office365 exchange server

I was initially connecting to an on-domain exchange server and retrieving attachment files from e-mails in my inbox. 我最初是连接到域内交换服务器,并从收件箱中的电子邮件中检索附件文件。 This worked great, it was authenticating, retrieving the files (even other folders). 这非常有效,它正在进行身份验证,并检索文件(甚至其他文件夹)。 Now I've switched to an Office365 exchange server. 现在,我已切换到Office365交换服务器。

I have read the documentation and understand that the following needs to be false and you have to pass through the credentials manually as you can see below. 我已经阅读了文档,并了解以下内容必须为假,并且您必须手动通过凭据,如下所示。

// Service.UseDefaultCredentials = true;
Service.Credentials = new WebCredentials(ExchangeEmail, ExchangePassword);

So I've done these changes, I've got my ExchangeService's ExchangeVersion on "Exchange2013_SP1. 因此,我做了这些更改,在“ Exchange2013_SP1”上安装了ExchangeService的ExchangeVersion。

From inspecting the Service after the .AutodiscoverUrl call, it can be seen that it's retrieving a url etc. So it looks like it is definitely connecting to the server. 通过在.AutodiscoverUrl调用之后检查服务,可以看出它正在检索url等。因此,看起来好像它确实已连接到服务器。 I'm out of ideas now, I've followed the msdn page for EWS Managed Api and can't quite figure out why it's now no longer picking out the e-mails. 我现在没有主意了,我关注了EWS Managed Api的msdn页面,无法完全弄清为什么现在不再选择电子邮件。

Another important point is I'm doing a filter search (which worked in the domain exchange). 另一个要点是,我正在执行过滤器搜索(在域交换中有效)。 The structure of the Domain e-mail is the same as the office365 e-mail. 域电子邮件的结构与office365电子邮件相同。

This is the snippet where I'm unable to find items from : 这是我无法从中找到项目的代码段:

var view = new ItemView(10, 0, OffsetBasePoint.Beginning)
                       {
                           PropertySet =
                               new PropertySet(
                               BasePropertySet.IdOnly,
                               EmailMessageSchema.Sender,
                               ItemSchema.DateTimeReceived)
                       };

        var filter = new SearchFilter.ContainsSubstring(EmailMessageSchema.From, FromEmailAddress);
        FindItemsResults<Item> results;

        do
        {
            results = Service.FindItems(vacancyFolderId, filter, view);

Another test I've done is to keep it simple and just try send an e-mail through the ews managed api. 我所做的另一项测试是保持简单,然后尝试通过ews托管api发送电子邮件。 That works as expected. 那按预期工作。 I'm suspecting there is a subtle change that needs making to my attachment retrieving code. 我怀疑需要对我的附件检索代码进行微妙的更改。 Perhaps it's https or something but there is no mention of that in the documentation. 也许是https或其他内容,但文档中没有提及。 There is only mention that you need to have https enabled for accessing exchange servers. 仅提及您需要启用https才能访问交换服务器。

There were 2 problems with the way I was trying to filter by the "from email address". 我尝试通过“发件人电子邮件地址”进行过滤的方式存在2个问题。

1st problem was what Jason mentions. 第一个问题是杰森提到的问题 In my ItemView I had included the PropertySet value 'EmailMessageSchema.Sender' and this isn't a string. 在我的ItemView中,我包括了PropertySet值'EmailMessageSchema.Sender',这不是字符串。 Changing that to 'EmailMessageSchema.From" made no difference when trying to filter on the Office365 exchange server. 尝试在Office365交换服务器上进行筛选时,将其更改为“ EmailMessageSchema.From”没有区别。

Note: Using this incorrect property set (.Sender) on a Domain exchange server still works for whatever weird reason. 注意:出于任何奇怪的原因,在域交换服务器上使用此错误的属性集(.Sender)仍然可以使用。

2nd Problem When querying the Office365 server with the following syntax to filter by : 第二个问题在使用以下语法查询Office365服务器时,其筛选依据:

var filter = new SearchFilter.ContainsSubstring(EmailMessageSchema.From, FromEmailAddress);

Does not work. 不起作用。 When inspecting the incoming From it's not an e-mail address it is a "Username/Domain/Otherthings/Admin Group/Etc/Etc" . 当检查来自非电子邮件地址的传入邮件时,它是“用户名/域/其他/管理组/ Etc / Etc”。

Solution Use the querystring filter. 解决方案使用querystring过滤器。

var querystring = "HasAttachments:true From:foo@bar.com Kind:email";

I hope this helps someone and saves them the frustration this has caused me. 我希望这可以帮助某人并挽救他们给我带来的挫败感。 From the documentation I've seen (SearchFilter.ContainsSubstring and the EWS Managed Api getting starting..) there isn't any mention of this. 从我看到的文档(SearchFilter.ContainsSubstring和EWS托管Api入门..)中,没有任何提及。

If I follow you, I think you're saying that FindItems returns no results. 如果我关注您,我想您是说FindItems返回任何结果。 Doing a ContainsSubstring filter on the Sender property is problematic (since Sender isn't a string property). Sender属性上执行ContainsSubstring过滤器是有问题的(因为Sender不是字符串属性)。 See EWS SearchFilter.ContainsSubstring to filter on Sender Email Address . 请参阅EWS SearchFilter.ContainsSubstring以过滤发件人电子邮件地址

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM