我用emailMessage架構在一個類似的系統,並沒有注意到這個問題,也許下面的幫助:
//creates an object that will represent the desired mailbox
Mailbox mb = new Mailbox(common.strInboxURL);
//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));
// exclude any silly returned emails
searchFilterCollection.Add(new SearchFilter.Not(new SearchFilter.ContainsSubstring(EmailMessageSchema.Subject, "Undeliverable")));
searchFilterCollection.Add(new SearchFilter.Not(new SearchFilter.ContainsSubstring(EmailMessageSchema.Subject, "Out of Office")));
ItemView view = new ItemView(100);
view.OrderBy.Add(ItemSchema.DateTimeReceived, SortDirection.Ascending);
// This results in a FindItem operation call to EWS.
FindItemsResults<Item> results = service.FindItems(fid, searchFilterCollection, view);
if (results.Count() > 0)
{
// set the prioperties we need for the entire result set
view.PropertySet = new PropertySet(
BasePropertySet.IdOnly,
ItemSchema.Subject,
ItemSchema.DateTimeReceived,
ItemSchema.DisplayTo, EmailMessageSchema.ToRecipients,
EmailMessageSchema.From, EmailMessageSchema.IsRead,
EmailMessageSchema.HasAttachments, ItemSchema.MimeContent,
EmailMessageSchema.Body, EmailMessageSchema.Sender,
ItemSchema.Body) { RequestedBodyType = BodyType.Text };
// load the properties for the entire batch
service.LoadPropertiesForItems(results, view.PropertySet);
forech (Microsoft.Exchange.WebServices.Data.Attachment attachment in email.Attachments)
{
if (attachment is FileAttachment)
{
FileAttachment fileAttachment = attachment as FileAttachment;
EWS是否通過['Attachment.Name']包含正確的'DisplayName'(http://msdn.microsoft.com/zh-cn/library/microsoft.exchange.webservices.data.attachment.name%28v = exchg.80%29.aspx)屬性? – SliverNinja 2012-07-09 16:30:17
是的。在當前的案例中,Attachment.Name顯示「Service Bericht」,這正是Outlook在DisplayName屬性中顯示的內容。但是我無法訪問任何顯示Outlook中FileName屬性值的值。我應該說,這些郵件是由服務創建的,並不是在Outlook中手動創建的。 – 2012-07-10 06:00:44
Outlook本身不使用EWS與Exchange Server交談,而是使用MAPI。有時候這會導致很小的差異(像這樣)。 – Halvard 2013-08-14 08:47:15