Created
July 6, 2024 13:41
-
-
Save aspose-com-gists/f8d4ff7f838c764681d5276e5a4f00ae to your computer and use it in GitHub Desktop.
Manage MAPI Properties using C#
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Retrieve and print custom properties | |
var customProperties = msg.GetCustomProperties(); | |
foreach (var customProperty in customProperties) | |
{ | |
Console.WriteLine($"Tag: {customProperty.Tag}"); | |
Console.WriteLine($"Canonical Name: {customProperty.Descriptor.CanonicalName}"); | |
Console.WriteLine($"Data Type: {customProperty.Descriptor.DataType}"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Retrieve and print the InternetMessageId property if it exists | |
if (msg.Properties[KnownPropertyList.InternetMessageId] != null) | |
{ | |
var property = msg.Properties[KnownPropertyList.InternetMessageId]; | |
Console.WriteLine($"Tag: {property.Tag}"); | |
Console.WriteLine($"Canonical Name: {property.Descriptor.CanonicalName}"); | |
Console.WriteLine($"Data Type: {property.Descriptor.DataType}"); | |
// Retrieve and print the property value if it is a string | |
if (property.Descriptor.DataType == PropertyDataType.String) | |
{ | |
var propertyValue = property.GetString(); | |
Console.WriteLine($"Value: {propertyValue}"); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Retrieve and print the PR_HASATTACH property if it exists | |
if (msg.Properties[MapiPropertyTag.PR_HASATTACH] != null) | |
{ | |
var property = msg.Properties[MapiPropertyTag.PR_HASATTACH]; | |
Console.WriteLine($"Tag: {property.Tag}"); | |
Console.WriteLine($"Data Type: {property.DataType}"); | |
// Retrieve and print the property value if it is a boolean | |
if (property.DataType == (int)MapiPropertyType.PT_BOOLEAN) | |
{ | |
var propertyValue = property.GetBoolean(); | |
Console.WriteLine($"Has Attachments: {propertyValue}"); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Retrieve and print the CurrentVersionName property | |
var namedProperty = msg.GetProperty(KnownPropertyList.CurrentVersionName); | |
if (namedProperty != null) | |
{ | |
Console.WriteLine($"Current Version Name: {namedProperty.GetString()}"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Load the email message from a file | |
var msg = MapiMessage.Load(@"D:\Aspose\Files\msg\test.msg"); | |
// Iterate through all MAPI properties and print their details | |
foreach (var mapiProperty in msg.Properties.Values) | |
{ | |
Console.WriteLine($"Tag: {mapiProperty.Tag}"); | |
Console.WriteLine($"Canonical Name: {mapiProperty.Descriptor.CanonicalName}"); | |
Console.WriteLine($"Data Type: {mapiProperty.Descriptor.DataType}"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
foreach (MapiNamedProperty mapiNamedProperty in msg.NamedProperties.Values) | |
{ | |
if (mapiNamedProperty.Descriptor is PidNamePropertyDescriptor pidNamePropertyDescriptor) | |
{ | |
Console.WriteLine($"GUID: {pidNamePropertyDescriptor.PropertySet}"); | |
Console.WriteLine($"Canonical Name: {pidNamePropertyDescriptor.CanonicalName}"); | |
Console.WriteLine($"Data Type: {pidNamePropertyDescriptor.DataType}"); | |
} | |
if (mapiNamedProperty.Descriptor is PidLidPropertyDescriptor pidLidPropertyDescriptor) | |
{ | |
Console.WriteLine($"GUID: {pidLidPropertyDescriptor.PropertySet}"); | |
Console.WriteLine($"Canonical Name: {pidLidPropertyDescriptor.CanonicalName}"); | |
Console.WriteLine($"Long ID: {pidLidPropertyDescriptor.LongId}"); | |
Console.WriteLine($"Data Type: {pidLidPropertyDescriptor.DataType}"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment