///<Summary> /// Add Custom Property ///</Summary> /// <param name="msg"></param> /// <param name="name"></param> /// <param name="value"></param> public static MapiProperty AddCustomProperty(this MapiMessage msg, string name, DateTime value) { var newProperty = MapiProperty.CreateMapiPropertyFromDateTime(msg.NamedPropertyMapping.GetNextAvailablePropertyId(MapiPropertyType.PT_SYSTIME), value); msg.AddCustomProperty(newProperty, name); return(newProperty); }
public static void Run() { //ExStart:SetMAPIProperties // The path to the File directory. string dataDir = RunExamples.GetDataDir_Outlook(); // Create a sample Message MapiMessage mapiMsg = new MapiMessage("*****@*****.**", "*****@*****.**", "This is subject", "This is body"); // Set multiple properties mapiMsg.SetProperty(new MapiProperty(MapiPropertyTag.PR_SENDER_ADDRTYPE_W, Encoding.Unicode.GetBytes("EX"))); MapiRecipient recipientTo = mapiMsg.Recipients[0]; MapiProperty propAddressType = new MapiProperty(MapiPropertyTag.PR_RECEIVED_BY_ADDRTYPE_W, Encoding.UTF8.GetBytes("MYFAX")); recipientTo.SetProperty(propAddressType); string faxAddress = "My Fax User@/FN=fax#/VN=voice#/CO=My Company/CI=Local"; MapiProperty propEmailAddress = new MapiProperty(MapiPropertyTag.PR_RECEIVED_BY_EMAIL_ADDRESS_W, Encoding.UTF8.GetBytes(faxAddress)); recipientTo.SetProperty(propEmailAddress); mapiMsg.SetMessageFlags(MapiMessageFlags.MSGFLAG_UNSENT | MapiMessageFlags.MSGFLAG_FROMME); mapiMsg.SetProperty(new MapiProperty(MapiPropertyTag.PR_RTF_IN_SYNC, BitConverter.GetBytes((long)1))); // Set DateTime property MapiProperty modificationTime = new MapiProperty(MapiPropertyTag.PR_LAST_MODIFICATION_TIME, ConvertDateTime(new DateTime(2013, 9, 11))); mapiMsg.SetProperty(modificationTime); mapiMsg.Save(dataDir + "MapiProp_out.msg"); //ExEnd:SetMAPIProperties }
///<Summary> /// Get Custom Properties ///</Summary> /// <param name="msg"></param> public static Dictionary <long, NamedMapiProperty> GetCustomProperties(this MapiMessage msg) { var customProperties = new Dictionary <long, NamedMapiProperty>(); // 0x00008540 is equivalent of MapiNamedPropertyId.PidLidPropertyDefinitionStream long tag = GetTagFromNamedProperty(0x00008540, msg); if (tag > 0) { byte[] data = msg.TryGetPropertyData(tag); List <string> names = GetCustomPropertiesNames(data); foreach (var name in names) { long tagCustomProp = GetTagFromNamedProperty(name, msg); if (tagCustomProp > 0) { MapiProperty customProp = msg.Properties[tagCustomProp]; if (customProp != null) { customProperties[tagCustomProp] = new NamedMapiProperty(name, customProp); } } } } return(customProperties); }
///<Summary> /// Add Custom Property ///</Summary> /// <param name="msg"></param> /// <param name="name"></param> /// <param name="type"></param> /// <param name="valueBytes"></param> public static MapiProperty AddCustomProperty(this MapiMessage msg, string name, MapiPropertyType type, byte[] valueBytes) { var newProperty = new MapiProperty(msg.NamedPropertyMapping.GetNextAvailablePropertyId(type), 0, valueBytes); msg.AddCustomProperty(newProperty, name); return(newProperty); }
public static void Run() { // The path to the File directory. // ExStart:RemovingPaswordProperty string dataDir = RunExamples.GetDataDir_Outlook(); PersonalStorage personalStorage = PersonalStorage.FromFile(dataDir + "PersonalStorage1.pst"); if (personalStorage.Store.Properties.Contains(MapiPropertyTag.PR_PST_PASSWORD)) { MapiProperty property = new MapiProperty(MapiPropertyTag.PR_PST_PASSWORD, BitConverter.GetBytes((long)0)); personalStorage.Store.SetProperty(property); } // ExEnd:RemovingPaswordProperty }
public static void Run() { string dataDir = RunExamples.GetDataDir_KnowledgeBase(); // Load mail message MapiMessage msg = MapiMessage.FromFile(dataDir + "message3.msg"); // ExStart:GetMAPIProperties MapiProperty mapi = msg.Properties[MapiPropertyTag.PR_SUBJECT_W]; if (mapi.Name.Trim().Length > 0) { // Display the MAPI property name and value Console.WriteLine(mapi.Name); Console.WriteLine(mapi.ToString()); } // ExEnd:GetMAPIProperties }
// ExStart:UpdatePSTCustomProperites public static void Run() { // Load the Outlook file string dataDir = RunExamples.GetDataDir_Outlook() + "Outlook.pst"; using (PersonalStorage personalStorage = PersonalStorage.FromFile(dataDir)) { FolderInfo testFolder = personalStorage.RootFolder.GetSubFolder("Inbox"); // Create the collection of message properties for adding or updating MapiPropertyCollection newProperties = new MapiPropertyCollection(); // Normal, Custom and PidLidLogFlags named property MapiProperty property = new MapiProperty(MapiPropertyTag.PR_ORG_EMAIL_ADDR_W,Encoding.Unicode.GetBytes("*****@*****.**")); MapiProperty namedProperty1 = new MapiNamedProperty(GenerateNamedPropertyTag(0, MapiPropertyType.PT_LONG),"ITEM_ID",Guid.NewGuid(),BitConverter.GetBytes(123)); MapiProperty namedProperty2 = new MapiNamedProperty(GenerateNamedPropertyTag(1, MapiPropertyType.PT_LONG),0x0000870C,new Guid("0006200A-0000-0000-C000-000000000046"),BitConverter.GetBytes(0)); newProperties.Add(namedProperty1.Tag, namedProperty1); newProperties.Add(namedProperty2.Tag, namedProperty2); newProperties.Add(property.Tag, property); testFolder.ChangeMessages(testFolder.EnumerateMessagesEntryId(), newProperties); } }
// ExStart:UpdatePSTCustomProperites public static void Run() { // Load the Outlook file string dataDir = RunExamples.GetDataDir_Outlook() + "Outlook.pst"; using (PersonalStorage personalStorage = PersonalStorage.FromFile(dataDir)) { FolderInfo testFolder = personalStorage.RootFolder.GetSubFolder("Inbox"); // Create the collection of message properties for adding or updating MapiPropertyCollection newProperties = new MapiPropertyCollection(); // Normal, Custom and PidLidLogFlags named property MapiProperty property = new MapiProperty(MapiPropertyTag.PR_ORG_EMAIL_ADDR_W, Encoding.Unicode.GetBytes("*****@*****.**")); MapiProperty namedProperty1 = new MapiNamedProperty(GenerateNamedPropertyTag(0, MapiPropertyType.PT_LONG), "ITEM_ID", Guid.NewGuid(), BitConverter.GetBytes(123)); MapiProperty namedProperty2 = new MapiNamedProperty(GenerateNamedPropertyTag(1, MapiPropertyType.PT_LONG), 0x0000870C, new Guid("0006200A-0000-0000-C000-000000000046"), BitConverter.GetBytes(0)); newProperties.Add(namedProperty1.Tag, namedProperty1); newProperties.Add(namedProperty2.Tag, namedProperty2); newProperties.Add(property.Tag, property); testFolder.ChangeMessages(testFolder.EnumerateMessagesEntryId(), newProperties); } }
public static void Run() { // ExStart:GetMAPIProperty // The path to the File directory. string dataDir = RunExamples.GetDataDir_Outlook(); // Load from file MapiMessage msg = MapiMessage.FromFile(dataDir + @"message.msg"); string subject; // Access the MapiPropertyTag.PR_SUBJECT property MapiProperty prop = msg.Properties[MapiPropertyTag.PR_SUBJECT]; // If the property is not found, check the MapiPropertyTag.PR_SUBJECT_W (which is a // Unicode peer of the MapiPropertyTag.PR_SUBJECT) if (prop == null) { prop = msg.Properties[MapiPropertyTag.PR_SUBJECT_W]; } // Cannot found if (prop == null) { Console.WriteLine("No property found!"); return; } // Get the property data as string subject = prop.GetString(); Console.WriteLine("Subject:" + subject); // Read internet code page property prop = msg.Properties[MapiPropertyTag.PR_INTERNET_CPID]; if (prop != null) { Console.WriteLine("CodePage:" + prop.GetLong()); } // ExEnd:GetMAPIProperty }
public static void Run() { string dataDir = RunExamples.GetDataDir_Outlook(); MapiMessage msg = MapiMessage.FromFile(dataDir + "message.msg"); // ExStart:SetAdditionalMAPIProperties // PT_MV_FLOAT, PT_MV_R4, mv.float IList <object> values = new List <object>(); values.Add((float)1); values.Add((float)2); msg.SetProperty(new MapiProperty(0x23901004, values)); // PT_MV_DOUBLE, PT_MV_R8 values = new List <object>(); values.Add((double)1); values.Add((double)2); msg.SetProperty(new MapiProperty(0x23901005, values)); // PT_MV_CURRENCY, mv.fixed.14.4 values = new List <object>(); values.Add((decimal)123.34); values.Add((decimal)289.45); msg.SetProperty(new MapiProperty(0x23901006, values)); // PT_MV_APPTIME values = new List <object>(); values.Add(30456.34); values.Add(40655.45); msg.SetProperty(new MapiProperty(0x23901007, values)); // PT_MV_I8, PT_MV_LONGLONG values = new List <object>(); values.Add((long)30456); values.Add((long)40655); msg.SetProperty(new MapiProperty(0x23901014, values)); // PT_MV_CLSID, mv.uuid values = new List <object>(); values.Add(Guid.NewGuid()); values.Add(Guid.NewGuid()); msg.SetProperty(new MapiProperty(0x23901048, values)); // PT_MV_SHORT, PT_MV_I2, mv.i2 values = new List <object>(); values.Add((short)1); values.Add((short)2); msg.SetProperty(new MapiProperty(0x23901002, values)); // PT_MV_SYSTIME values = new List <object>(); values.Add(DateTime.Now); values.Add(DateTime.Now); msg.SetProperty(new MapiProperty(0x23901040, values)); // PT_MV_BOOLEAN values = new List <object>(); values.Add(true); values.Add(false); msg.SetProperty(new MapiProperty(0x2390100b, values)); // PT_MV_BINARY values = new List <object>(); values.Add(Guid.NewGuid().ToByteArray()); values.Add(new byte[] { 1, 2, 4, 5, 6, 7, 5, 4, 3, 5, 6, 7, 8, 6, 4, 3, 4, 5, 6, 7, 8, 6, 5, 4, 3, 7, 8, 9, 0, 2, 3, 4, }); msg.SetProperty(new MapiProperty(0x23901102, values)); // PT_NULL msg.SetProperty(new MapiProperty(0x67400001, new byte[1])); MapiMessage message = new MapiMessage("*****@*****.**", "*****@*****.**", "subj", "Body of test msg"); // PT_MV_LONG values = new List <object>(); values.Add((int)4); MapiProperty property = new MapiProperty(message.NamedPropertyMapping.GetNextAvailablePropertyId(MapiPropertyType.PT_MV_LONG), values); message.NamedPropertyMapping.AddNamedPropertyMapping(property, 0x00008028, new Guid("00062004-0000-0000-C000-000000000046")); message.SetProperty(property); // OR you can set the custom property (with the custom name) message = new MapiMessage("*****@*****.**", "*****@*****.**", "subj", "Body of test msg"); values = new List <object>(); values.Add((int)4); property = new MapiProperty(message.NamedPropertyMapping.GetNextAvailablePropertyId(MapiPropertyType.PT_MV_LONG), values); message.AddCustomProperty(property, "customProperty"); //PT_FLOAT //Please note that you need explicit cast to float value for this to work float floatValue = (float)123.456; MapiMessage newMsg = new MapiMessage(); long floatTag = newMsg.NamedPropertyMapping.GetNextAvailablePropertyId(MapiPropertyType.PT_FLOAT); Guid guid = Guid.NewGuid(); MapiProperty newMapiProperty = new MapiProperty(floatTag, BitConverter.GetBytes(floatValue)); newMsg.NamedPropertyMapping.AddNamedPropertyMapping(newMapiProperty, 12, guid); newMsg.SetProperty(newMapiProperty); // ExEnd:SetAdditionalMAPIProperties }
///<Summary> /// Named Mapi Property ///</Summary> public NamedMapiProperty(string name, MapiProperty customProp) { Name = name; Property = customProp; }