简体   繁体   English

将属性永久存储在mailitem和相关的.msg文件中

[英]store permanently properties in mailitem and related .msg file

I need to save permanently some custom information inside an Outlook Mailitem and retrieve them back. 我需要将一些自定义信息永久保存在Outlook Mailitem中,然后将其取回。 My case scenario is the following: I select an email in Outlook 2013 explorer, write inside that email some information, save it on my disk as .msg file, delete the email from the Inbox Outlook folder, open the .msg file as Outlook.MailItem and read that information in order to keep them or change them. 我的案例情况如下:我在Outlook 2013资源管理器中选择一封电子邮件,在该电子邮件中写一些信息,将其另存为.msg文件存储在我的磁盘上,从“收件箱” Outlook文件夹中删除该电子邮件,将.msg文件作为Outlook打开。 MailItem并读取该信息以保留或更改它们。

I'm using the Outlook.ItemProperties.Add() method to add a custom ItemProperty inside the selected MailItem. 我正在使用Outlook.ItemProperties.Add()方法在所选MailItem中添加自定义ItemProperty。

When I get a MailItem from the .msg I'm not able to find that properties. 当我从.msg获取MailItem时,找不到该属性。

I've used OutlookSpy ->Miscellaneous->OpenIMsgOnIstg function to check the .msg and I've noted that all properties are in the GetProps tab. 我已经使用OutlookSpy- > Miscellaneous-> OpenIMsgOnIstg函数来检查.msg,并且我注意到所有属性都在GetProps选项卡中。

My question is: How can I read the properties? 我的问题是:如何读取属性?

Here is the code to write the properties and save the mail as .msg: 这是编写属性并将邮件另存为.msg的代码:

Outlook.Application outApp= new Outlook.Application();
Outlook.MailItem mail= null;
try { mail = (Outlook.MailItem)outApp.ActiveInspector().CurrentItem; }
catch {
   if (outApp.ActiveExplorer().Selection.Count > 0)
      mail = (Outlook.MailItem)outApp .ActiveExplorer().Selection[1];
   else { // ERROR  }
}
Outlook.ItemProperty prop01 = mail.ItemProperties.Add("MyProperty01", Outlook.OlUserPropertyType.olText);
prop01.Value = "hola";
Outlook.ItemProperty prop02 = mail.ItemProperties.Add("MyProperty02", Outlook.OlUserPropertyType.olNumber);
prop02.Value = 23;
mail.Save();
mail.SaveAs(@"C:\WorkSpace\mail.msg", Outlook.OlSaveAsType.olMSG);
if (mail != null) Marshal.ReleaseComObject(mail);
if (outlookObj != null) Marshal.ReleaseComObject(outApp );

Here is my code to read the properties from the .msg after I've deleted the email in Outlook: 这是我在Outlook中删除电子邮件后从.msg中读取属性的代码:

Outlook.Application outApp= new Outlook.Application();
Outlook.MailItem msgMail=(Outlook.MailItem)outApp.CreateItem(Outlook.OlItemType.olMailItem);
msgMail = (Outlook.MailItem)outApp.Session.OpenSharedItem(@"C:\WorkSpace\mail.msg");
Outlook.ItemProperties mailProps = msgMail.ItemProperties;
Outlook.ItemProperty pr = mailProps["MyProperty01"]; // pr IS NULL

But OutlookSpy shows the properties are in the .msg file. 但是OutlookSpy 显示属性位于.msg文件中。

使用Mailitem.PropertyAccessor.GetProperty并传递OutlookSpy显示的DASL属性名称。

我已经解决了这个绕过解决方案的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM