C#捕获Outlook电子邮件正文

时间:2013-10-09 17:59:55

标签: c# outlook-2007

编辑#2 ---- 它编译得很好,但我得到一个调试错误: 必须在此行上设置ExchangeService上的URL属性 在这行代码 'FindItemsResults findResults = service.FindItems(WellKnownFolderName.Inbox,new ItemView(128));' 结束编辑#2 ----

编辑--- 呃 - 我没有意识到我需要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#阅读电子邮件正文的非常清晰的说明方式?

1 个答案:

答案 0 :(得分:1)

认为您缺少对MS Exchange程序集Microsoft.Exchange.WebServices.dll

的引用

或使用声明using Microsoft.Exchange.WebServices.Data;

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

ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010);

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

获取程序集

MSDN个文档开始使用+ Code samples

相关问题