Adding string property to a MapiMessage

Hi,

With respect to adding properties to a Mapimessage, can you please share:

  1. What is the statndard way of adding a string property to a Mapimessage via this API?

  2. What is the best way to add a float value property to mapimessage?

  3. What is the best way to add an integer value property to the mapi message?

  4. What is the best way to add a date value to property to the mapi message?

  5. What is the way to add a date value to property set of a mapi message?

Hi Acton,

Thank you for contacting Aspose support team.

Following are sample code for setting different type of properties in a MapiMessage. Please give it a try and let us know the feedback.

//1.What is the statndard way of adding a string property to a Mapimessage via this API?

//Option 1
MapiMessage mapi = new MapiMessage();
MapiProperty msgClass = new MapiProperty(MapiPropertyTag.PR_MESSAGE_CLASS_W, Encoding.Unicode.GetBytes("IPM.Post.RSS"));
mapi.SetProperty(msgClass);

//Option 2
//mapi.SetStringPropertyValue(MapiPropertyTag.PR_MESSAGE_CLASS, "IPM.Post.RSS");
//2. What is the best way to add a float value property to mapimessage?

MapiMessage message2 = new MapiMessage();
long mapiPropertyTag2 = message2.NamedPropertyMapping.GetNextAvailablePropertyId(MapiPropertyType.PT_DOUBLE);
Guid mapiPropertyGuid2 = new Guid("6ed8da90-450b-101b-98da-00aa003f1305");//Any random Guid
MapiProperty mapiProperty2 = new MapiProperty(mapiPropertyTag2, BitConverter.GetBytes(123.456));
message2.NamedPropertyMapping.AddNamedPropertyMapping(mapiProperty2, 12, mapiPropertyGuid2);
message2.SetProperty(mapiProperty2);

//3. What is the best way to add an integer value property to the mapi message?
MapiTask task = new MapiTask("subj", "body", new DateTime(2015, 4, 30), DateTime.Now.AddHours(1));
task.State = MapiTaskState.NotAssigned;

//Set the URGENT priority
task.SetProperty(new MapiProperty(MapiPropertyTag.PR_PRIORITY, BitConverter.GetBytes((long)1)));

//4. What is the best way to add a date value to property to the mapi message?
//5. What is the way to add a date value to property set of a mapi message?
static void test()
{
    MapiMessage outlookMsg = new MapiMessage();
    MapiProperty ClientSubmitTime = new MapiProperty(MapiPropertyTag.PR_CLIENT_SUBMIT_TIME, convertDateTime(new DateTime(2013, 9, 11)));
    outlookMsg.SetProperty(ClientSubmitTime);
}

private static byte[] convertDateTime(DateTime t)
{
    long filetime = t.ToFileTime();
    byte[] d = new byte[8];
    d[0] = (byte)(filetime & 0xFF);
    d[1] = (byte)((filetime & 0xFF00) >> 8);
    d[2] = (byte)((filetime & 0xFF0000) >> 16);
    d[3] = (byte)((filetime & 0xFF000000) >> 24);
    d[4] = (byte)((filetime & 0xFF00000000) >> 32);
    d[5] = (byte)((filetime & 0xFF0000000000) >> 40);
    d[6] = (byte)((filetime & 0xFF000000000000) >> 48);
    d[7] = (byte)(((ulong)filetime & 0xFF00000000000000) >> 56);
    return d;
}