【发布时间】:2014-04-09 10:47:06
【问题描述】:
我在 c# 中使用 Exchaneg Web Services 从 Exchange 2010 的邮箱中检索所有电子邮件。
我将每封电子邮件的所有信息放入一个数据表中,然后返回给调用函数。
我还需要每封电子邮件的唯一项目 ID,以便完成后我可以在 Exchange 框中将电子邮件标记为已读。
我试过这个:
// As a best practice, limit the properties returned to only those that are required.
PropertySet propSet = new PropertySet(BasePropertySet.IdOnly, ItemSchema.Subject);
// Bind to the existing item by using the ItemId.
// This method call results in a GetItem call to EWS.
ItemId itemID = Item.Bind(service, itemId, propSet);
但它不会编译,而且我不明白出了什么问题,我需要项目 ID,以便我可以存储它并稍后找到相同的项目以将其标记为已读
这里是主要的代码块:
//creates an object that will represent the desired mailbox
Mailbox mb = new Mailbox(common.strInboxURL); // new Mailbox(targetEmailAddress); @"bbtest@bocuk.local"
//creates a folder object that will point to inbox fold
FolderId fid = new FolderId(WellKnownFolderName.Inbox, mb);
//this will bind the mailbox you're looking for using your service instance
Microsoft.Exchange.WebServices.Data.Folder inbox = Microsoft.Exchange.WebServices.Data.Folder.Bind(service, fid);
SearchFilter.SearchFilterCollection searchFilterCollection = new SearchFilter.SearchFilterCollection(LogicalOperator.And);
searchFilterCollection.Add(new SearchFilter.IsEqualTo(EmailMessageSchema.IsRead, false));
searchFilterCollection.Add(new SearchFilter.IsEqualTo(EmailMessageSchema.HasAttachments, true));
searchFilterCollection.Add(new SearchFilter.ContainsSubstring(EmailMessageSchema.Sender, "@bankofcyprus.co.uk"));
// add the exceptions
for (int iEx = 0; iEx < e2c.emailExceptions.Count; iEx++)
{
searchFilterCollection.Add(new SearchFilter.Not(new SearchFilter.ContainsSubstring(EmailMessageSchema.Subject, e2c.emailExceptions[iEx])));
}
ItemView view = new ItemView(100);
view.OrderBy.Add(ItemSchema.DateTimeReceived, SortDirection.Ascending);
//view.PropertySet = new PropertySet(
// BasePropertySet.IdOnly,
// ItemSchema.Subject,
// ItemSchema.DateTimeReceived);
// Find the first email message in the Inbox that has attachments. This results in a FindItem operation call to EWS.
FindItemsResults<Item> results = service.FindItems(WellKnownFolderName.Inbox, searchFilterCollection, view);
foreach (EmailMessage email in results)
// looping through all the emails
{
emailSenderName = email.Sender.Name;
sEmailSubject = email.Subject;
emailAttachmentsCount = email.Attachments.Count;
emailDisplayTo = email.DisplayTo;
emailHasAttachments = email.HasAttachments;
email.Load(new PropertySet(ItemSchema.Body) { RequestedBodyType = BodyType.Text });
sEmailBody = email.Body;
// As a best practice, limit the properties returned to only those that are required.
PropertySet propSet = new PropertySet(BasePropertySet.IdOnly, ItemSchema.Subject);
// Bind to the existing item by using the ItemId.
// This method call results in a GetItem call to EWS.
ItemId itemID = Item.Bind(service, itemId, propSet);
//email.get .Load(new PropertySet(ItemId):
email.Load(new PropertySet(ItemSchema.DateTimeReceived));
DataRow row = emails.NewRow();
row["displayname"] = emailDisplayTo;
... (cut for brevity!
email.Load(new PropertySet(EmailMessageSchema.Attachments));
请问如何获取商品 ID?
【问题讨论】:
标签: c# email exchangewebservices exchange-server-2010