编辑#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
编辑 - -
我在这里看到了帖子——如何使用 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# 阅读电子邮件正文的非常清晰的说明方法如何?