Aspose Email .NET

Hi,

We are planning to purchase Aspose Email license. We came across one issue even after taking the temporary license, we couldn’t figure out any unique id to identify message. Can you help us if we have any such unique property in message.

Thanks,
Spandana

@Spandana_Enjala

Can you please provide more details about the type of message you are working with and the specific properties you are looking for?

normal msg file and expecting a unique identifier property for Message

@Spandana_Enjala ,

In standalone .msg files, there is no global unique identifier for messages. Identifiers are assigned only when messages are stored in a repository, such as a server mailbox or a local storage file like a PST. Moreover, the identifier is unique only within the scope of that specific storage.

If you need to uniquely identify messages in .msg files, you can define a custom mechanism by assigning a custom property to the message using the AddCustomProperty method in MapiMessage. When you save the file, the custom property will also be stored.

Here’s an example:

var msg = new MapiMessage("from@domain.com", "to@domain.com", "subject", "body");

// Add a custom `msgId` property with value "f921dab48a374dacafc76c99ae931434"  that represents an unique identifier 
msg.AddCustomProperty(MapiPropertyType.PT_UNICODE, Encoding.Unicode.GetBytes("f921dab48a374dacafc76c99ae931434"), "msgId");

// Save the .msg file
msg.Save(@"out.msg");

Later, you can retrieve the saved identifier using the GetCustomProperties method:

var msg2 = MapiMessage.Load(@"out.msg");

// Retrieve custom properties
var properties = msg2.GetCustomProperties();

foreach (var prop in properties.Values)
{
    if (prop.Descriptor.Name == "msgId")
    {
        var value = (string)prop.GetValue();
        Console.WriteLine($"Unique Identifier: {value}");
    }
}

This approach ensures that you have a unique identifier embedded in each .msg file that you create or manage.

1 Like