【问题标题】:Extended property not adhering to EmailMessage扩展属性不遵守 EmailMessage
【发布时间】:2019-03-31 14:56:02
【问题描述】:

我正在运行的代码旨在添加扩展属性和值。似乎运行良好。当我遍历 MailItems 时,我没有看到任何扩展属性的证据。

要扩展的代码:

EmailMessage email2 = EmailMessage.Bind(service, result.Items[0].Id);
Guid MyPropertySetId = new Guid("{C11FF724-AA03-4555-9952- 
8FA248A11C3E}");
ExtendedPropertyDefinition extendedPropertyDefinition = new 
ExtendedPropertyDefinition(MyPropertySetId, "ServiceCat", 
MapiPropertyType.String);
email2.SetExtendedProperty(extendedPropertyDefinition, "Level2 big daddy");
email2.Update(ConflictResolutionMode.AlwaysOverwrite);

读取扩展属性的代码:

   foreach (Item item in result.Items)
        {
            Console.WriteLine(item.Subject);
            if (item.ExtendedProperties.Count > 0)
            {
                // Display the name and value of the extended property.
                foreach (ExtendedProperty extendedProperty in item.ExtendedProperties)
                {
                    Console.WriteLine(" Extended Property Name: " + extendedProperty.PropertyDefinition.Name);
                    Console.WriteLine(" Extended Property Value: " + extendedProperty.Value);
                }
            }
        }

我已尝试重新连接以遍历电子邮件以查看是否存在扩展属性,但数组长度仍为 0。即foreach 永远不会启动。

我假设扩展的 preoprty 保存在交换“email2.Update(ConflictResolutionMode.AlwaysOverwrite)”并且应该能够被读回

任何建议表示赞赏。

【问题讨论】:

    标签: c# exchangewebservices extended-properties


    【解决方案1】:

    您需要先使用属性集加载扩展属性,然后才能在消息上枚举它,例如

            PropertySet psPropSet = new PropertySet();
            psPropSet.Add(extendedPropertyDefinition );
            ItemView itemView = new ItemView(1000);
            itemView.PropertySet = psPropSet;
    

    然后您可以使用 TryGetProperty 来获取扩展属性(如果已设置)

    【讨论】:

    • 谢谢,我可以看到该属性正在通过。我希望将扩展属性添加到许多不同组邮箱的邮件项目中。在稍后阶段,我希望将值附加到属性。我可以使用相同的 GUID 跨邮箱附加扩展属性吗?
    • 或者,我可以使用:
    • 您应该使用相同的 GUID 不要开始创建大量随机扩展属性,您只需要一个,否则您将开始遇到扩展属性耗尽的问题。你需要为你想要做的事情定义一个,它会在你需要的任意数量的邮箱中工作。
    猜你喜欢
    • 1970-01-01
    • 2011-04-30
    • 2011-09-18
    • 1970-01-01
    • 1970-01-01
    • 2020-06-08
    • 2013-07-08
    • 2012-05-23
    • 1970-01-01
    相关资源
    最近更新 更多