【问题标题】:Outlook.MailItem.UserProperty disappear after sending mailOutlook.MailItem.UserProperty 发送邮件后消失
【发布时间】:2016-11-21 16:39:56
【问题描述】:

我正在尝试在创建 MailItem 时将自定义 UserProperty 添加到它。

我将附件的哈希作为 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 消失了,请帮助我并告诉 :)

【问题讨论】:

  • 您使用哪种消息存储?命名属性 blob 是否与存储属性值的属性一起消失了(单击 OutlookSpy 中的 IMessage)?

标签: c# .net outlook


【解决方案1】:

经过一番努力,我解决了我的问题。

发送邮件后删除用户属性。但我使用 MailItem.PropertyAccessor.SetProperty 而不是 UserProperties

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");

最后我解析字符串以获取我的数据。

希望对大家有帮助:)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-11-23
    • 2014-08-20
    • 2014-11-18
    • 2016-04-11
    • 1970-01-01
    • 1970-01-01
    • 2017-02-09
    • 2016-09-07
    相关资源
    最近更新 更多