2016-11-04 79 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我为了得到我的数据解析字符串。

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