2016-03-21 38 views
0

我已經創建了一個Outlook自定義表單,並將它發送到我的收件箱。閱讀C#中的電子郵件表單數據#

現在,在我的代碼中,

 ExchangeService exchange = new ExchangeService(ExchangeVersion.Exchange2010_SP1); 
     exchange.UseDefaultCredentials = true; 
     exchange.AutodiscoverUrl("[email protected]", RedirectionUrlValidationCallback); 

     TimeSpan ts = new TimeSpan(0, -1, 0, 0); 
     DateTime date = DateTime.Now.Add(ts); 
     SearchFilter.IsGreaterThanOrEqualTo filter = new SearchFilter.IsGreaterThanOrEqualTo(ItemSchema.DateTimeReceived, date); 

     if (exchange != null) 
     { 
      Folder inbox = Folder.Bind(exchange, WellKnownFolderName.Inbox); 
      SearchFilter sf = new SearchFilter.SearchFilterCollection(LogicalOperator.And, new SearchFilter.IsEqualTo(EmailMessageSchema.IsRead, false)); 
      ItemView view = new ItemView(1); 
      FindItemsResults<Item> findResults = exchange.FindItems(WellKnownFolderName.Inbox, sf, view); 

      foreach (Item item in findResults) 
      { 
       EmailMessage message = EmailMessage.Bind(exchange, item.Id); 
       string messageBody = message.Body; 

我可以得到主題,身體等,但我如何閱讀自定義窗體中的字段?

所以我有一個字段叫做textbox1。

在此先感謝。

回答

3

您需要知道您的自定義窗體在Outlook中創建的MAPI屬性的詳細信息。您可以使用像MFCMapi或Outlook Spy這樣的Mapi編輯器輕鬆找到此信息。一旦你知道了GUID,標籤信息,你只需要定義,並告訴EWS返回的財產,以你如最有可能像

ExtendedPropertyDefinition CustomProperty = new ExtendedPropertyDefinition(DefaultExtendedPropertySet.PublicStrings, "CustomPropertyName", MapiPropertyType.String); 
PropertySet ItemPropSet = new PropertySet(BasePropertySet.FirstClassProperties); 
ItemPropSet.Add(CustomProperty); 
EmailMessage message = EmailMessage.Bind(exchange, item.Id,ItemPropSet); 

又見https://msdn.microsoft.com/en-us/library/office/dd633697(v=exchg.80).aspx

乾杯 格倫

+0

輝煌。謝謝。 – griegs