2016-11-04 80 views
1

我試圖在創建它時將自定義UserProperty添加到MailItem。發送郵件後Outlook.MailItem.UserProperty消失

我將附件的Hash作爲UserProperty添加到我的MailItem對象中。 然後我在Outlook中打開我的新MailItem。

mi = olApp.CreateItem(Outlook.OlItemType.olMailItem) as Outlook.MailItem; 
      Outlook.UserProperties mailUserProperties = null; 
      Outlook.UserProperty mailUserProperty = null; 

      mi.Attachments.Add(file.FilePath); 
      mailUserProperties = mi.UserProperties; 
      mailUserProperty = mailUserProperties.Add("AttachementsHash", Outlook.OlUserPropertyType.olText); 
      mailUserProperty.Value = file.Hash; 
      mi.Save(); 
      mi.Display(); 

如果我使用OutlookSpy檢查MailItem.UserProperties之前發送我看到我的郵件有一個UserProperty。

然後我點擊Outlook中的「發送郵件」,然後在SentItems文件夾中查看我的郵件。 我可以看到UserProperties.Count == 0,

如果有誰知道爲什麼我的UserProperty消失了,請幫助我,告訴:)

+0

你使用的是什麼類型的消息存儲?命名屬性blob是否與存儲屬性值的屬性一起(單擊OutlookSpy中的IMessage)? –

回答

2

有了很大的功夫我解決我的問題。

發送郵件後,UserProperties被刪除。但在UserProperties代替我用MailItem.PropertyAccessor.SetProperty

MSDN Documentation of Property Accessor

 string prop = "http://schemas.microsoft.com/mapi/string/{00020386-0000-0000-C000-000000000046}/PropertyName"; 
     mi.PropertyAccessor.SetProperty(prop, propertyValue.ToString()); 

,然後在事件 'ItemAdd' 我查了一下,如果項目被添加到sentItems。 如果它被添加到sentItems我讀到使用這類建築性質:

Outlook.MailItem AddedMail = item as Outlook.MailItem; 
        string attachmentProperty = AddedMail.PropertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x007D001E"); 

然後finnally我爲了得到我的數據解析字符串。

我希望它能幫助任何人:)