2013-10-09 67 views
4

编辑#的机身2 ---- 它编译罚款,但我得到的调试错误: 上ExchangeService URL属性必须在该行 设置开启代码 这条线'FindItemsResults findResults = service.FindItems(WellKnownFolderName.Inbox,new ItemView(128));'' End EDIT#2 ----C#来捕获Outlook电子邮件

编辑--- 呃 - 我没有意识到我需要10个重点发布图片...让我给出一些错误。

1) Type or namespace 'FindItemsResults' could not be found
2) Type or namespace name 'Item' could not be found
3) The name 'service' does not exist in the current context
4) Type or namespace 'ItemView' could not be found

编辑----

我看到了张贴在这里 - How to get email body, receipt, sender and CC info using EWS?,并期待在此采码

public class MailItem 
{ 
    public string From; 
    public string[] Recipients; 
    public string Subject; 
    public string Body; 
} 

public MailItem[] GetUnreadMailFromInbox() 
{ 
    FindItemsResults<Item> findResults = service.FindItems(WellKnownFolderName.Inbox, new ItemView(128)); 
    ServiceResponseCollection<GetItemResponse> items = 
     service.BindToItems(findResults.Select(item => item.Id), new PropertySet(BasePropertySet.FirstClassProperties, EmailMessageSchema.From, EmailMessageSchema.ToRecipients)); 
    return items.Select(item => 
    { 
     return new MailItem() 
     { 
      From = ((Microsoft.Exchange.WebServices.Data.EmailAddress)item.Item[EmailMessageSchema.From]).Address, 
      Recipients = ((Microsoft.Exchange.WebServices.Data.EmailAddressCollection)item.Item[EmailMessageSchema.ToRecipients]).Select(recipient => recipient.Address).ToArray(), 
      Subject = item.Item.Subject, 
      Body = item.Item.Body.ToString(), 
     }; 
    }).ToArray(); 
} 

但我越来越多编译错误。如何使用C#阅读电子邮件的正文非常明确的说明方式?

+2

发布你的错误,在这里没有人能读心术所以没有这些信息,我们不能帮你。 – Sorceri

+0

将一些错误添加到原始文章中。对不起,我没有意识到发布图片需要10个重点。我认为这是我的原始帖子。 – user2676140

+0

我认为它应该是'FindItems'而不是'findItems' – Icemanind

回答

1

认为你是缺少的MS Exchange组件Microsoft.Exchange.WebServices.dll

引用或using语句using Microsoft.Exchange.WebServices.Data;

对于(3)您需要声明并初始化服务对象如图所示链接的问题。

ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010); 

注意:您可以从Microsoft Exchange Web Services Managed API 2.0

MSDN文档获取组件上手+ Code samples

+0

我添加了推荐的.dll文件,但并未删除该错误? – user2676140

+0

你有没有把使用说明? '使用Microsoft.Exchange.WebServices.Data;' – Amitd

+0

是的。它在使用语句中强调了“Exchange”一词,并告诉我“Exchange”在名称空间Microsoft中不存在。 – user2676140