使用 MAPI 属性
Contents
[
Hide
]
访问和设置 Outlook MAPI 属性
MapiProperty 类表示一个 MAPI 属性,包含:
- Name:表示属性名称的字符串。
- Tag:表示属性标签的长整数。
- Data:表示属性数据的字节数组。
使用 MAPI 属性标签获取 MAPI 属性
获取 MAPI 属性:
- 通过从文件或流加载来创建 MapiMessage 实例。
- 通过 MapiPropertyTag 键从 MapiMessage.Properties 获取 MapiProperty。
- 通过 GetX 方法获取 MapiProperty 的数据。
以下代码片段展示如何使用 MAPI 属性标签获取 MAPI 属性。
设置 MAPI 属性
以下代码片段展示了如何设置 MAPI 属性。
其中 convertDateTime 方法的定义如下:
从 Outlook MSG 文件读取命名的 MAPI 属性
Aspose.Email 提供了一套用于处理 MSG 文件的 API,包括提取已命名的 MAPI 属性。
从 MSG 文件读取命名的 MAPI 属性
要读取命名的 MAPI 属性,我们可以使用 named_properties 属性。 MapiMessage 类。以下代码示例展示了如何加载消息,检索所有已命名的 MAPI 属性,遍历每个属性以检查其值:
import aspose.email as ae
msg = ae.mapi.MapiMessage.load("my.msg")
# Get all named MAPI properties
properties = msg.named_properties.values
# Read all properties in foreach loop
for prop in properties:
# Read any specific property
if prop.descriptor.canonical_name == "PidLidSideEffects":
print(f"{prop.descriptor.canonical_name} = {prop}")
if prop.descriptor.canonical_name == "PidLidInternetAccountName":
print(f"{prop.descriptor.canonical_name} = {prop}")
从附件读取命名的 MAPI 属性
Aspose.Email 可以检索附件的所有已命名 MAPI 属性。以下代码示例展示了如何从附件中读取已命名的 MAPI 属性:
import aspose.email as ae
msg = ae.mapi.MapiMessage.load("my.msg")
# Get all named MAPI properties
attach_properties = msg.attachments[0].named_properties.values
# Read all properties in foreach loop
for prop in attach_properties:
# Read any specific property
if prop.descriptor.name == "AttachmentOriginalUrl":
print(f"{prop.descriptor.name} = {prop.get_string()}")
if prop.descriptor.name == "AttachmentWasSavedToCloud":
print(f"{prop.descriptor.name} = {prop.get_boolean()}")
从 MSG 和附件中移除属性
此代码示例演示了创建包含正文内容和附件消息文件的 Outlook MSG 消息。它还展示了如何删除已创建消息中的附件属性。
import aspose.email as ae
# create an MSG
msg = ae.mapi.MapiMessage("from@doamin.com", "to@domain.com", "subject", "body");
msg.set_body_content("<html><body><h1>This is the body content</h1></body></html>", ae.mapi.BodyContentType.HTML)
# load message and add it to created MSG as attachment
attachment = ae.mapi.MapiMessage.load(attach.msg")
msg.attachments.add("Outlook2 Test subject.msg", attachment)
# count of attachment properties before removal
print(f"Before removal = {msg.attachments[0].properties.count}")
# Delete anyone attachment property
msg.attachments[0].remove_property(923467779)
# count of attachment properties after removal
print(f"Before removal = {msg.attachments[0].properties.count}")