在草稿消息中存储 VSTO Outlook 插件的状态

问题描述 投票:0回答:1

我尝试将 VSTO 插件的状态存储在草稿电子邮件中,但没有成功。 我在 MailItem.Write 事件上添加用户属性(当我保存草稿消息时),但在 MailItem.Open 事件上打开保存的草稿时我没有检索到任何内容。

一些代码:

public bool Application_ItemWrite(Object Item)
    {
    ...

    Outlook.MailItem mailItem = (Outlook.MailItem)Item;
    
    UserProperty userProp = mailItem.UserProperties.Add("blabla", OlUserPropertyType.olYesNo, false);
    userProp.Value = true;

    mailItem.Save();

    // Check
    userProp = null;

    userProp = mailItem.UserProperties.Find("blabla");
    if (userProp != null)
        bool value = userProp.Value;
}

public bool Application_ItemOpen(Object Item)
{
    ...

    Outlook.MailItem mailItem = (Outlook.MailItem)Item;

    UserProperty userProp = mailItem.UserProperties.Find("blabla", true);

    if (userProp != null)
        bool value = userProp.Value;
}

我在 Visual 下启动插件,在 Outlook 中我只是创建一封新邮件,关闭它并回答“是”以保存草稿...

我可以在调试器下看到 Application_ItemWrite 的检查部分中 blabla 属性的正确值

在Application_ItemOpen中,userProp始终为null,因为似乎找不到该属性:-(

最后一个问题:Save 语句重复草稿邮件:-( 但不保存任何属性。

任何帮助表示赞赏

c# outlook vsto
1个回答
0
投票

首先,没有

Application.ItemWrite
事件。有
MailItem.Write
事件,但它传递
Cancel
(通过 ref)参数,而不是
Item
Application.ItemOpen
同上:没有这样的事件。

尝试删除对

mailItem.Save()
的调用 - 您的消息将在事件处理程序运行后立即保存,除非您将
Cancel
参数设置为 true。尝试使用 OutlookSpy (我是作者 - 单击 IMessage 按钮)来确保您的自定义道具确实已保存。

读取自定义 prop 时,由于没有

Application.ItemOpen
事件,因此可以使用
Application.Inspectors.NewInspector
事件或
Application.ActiveExplorer.SelectionChange
事件。
Application.ItemLoad
事件不是一个好的选择 - 它触发得太频繁。

请记住,用户属性可能会导致 Outlook 以 RTF (TNEF) 格式发送 - 为了确保不会发生这种情况,请使用

MailItem.PropertyAccessor.SetProperty/GetProperty
。您可以使用与自定义属性相同的 DASL 属性(请参阅 OutlookSpy 中的 DASL 名称)。

© www.soinside.com 2019 - 2024. All rights reserved.