Free Support Forum - aspose.com

Extracting Contact Properties using Aspose.Email (C#)

I need to extract contact emaiil1, contact email2 , display as fields from the msg file with message class Ipm.contact I didn’t find any exact property information to extract these fields from file. Can you please help which mapiproperty tag should i use to extract these fields?
Screenshot (69).png (87.8 KB)
Screenshot (68).png (89.5 KB)

@alishasharma,

I have observed the issue shared by you and request you to please share the source with requirements and we will try to provide the sample code based on that after working over them.

@mudassir.fayyaz,
Please find the sample ipm.contact file here
I tried to use following code to extract FileAs property, not sure if this property is exactly made for this purpose. Apart form this, I need to extract contact email1, email2 fields from this file(also other similar kinds of file)

 MapiMessage message = MapiMessage.FromFile(filePath);
 var mapiProperties = message.Properties;
 MapiProperty prop = null;
 prop = mapiProperties[MapiPropertyTag.PR_EMS_AB_FOLDER_PATHNAME_W] ?? mapiProperties[MapiPropertyTag.PR_EMS_AB_FOLDER_PATHNAME_A]; 
 if(prop != null)
   string FileAs = RemoveNullChars(prop.GetString());

@alishasharma,

Can you please try to use following sample code on your end and share feedback with us if there is still an issue. Following code will help you to achieve your requirements.

MapiMessage msg = MapiMessage.FromFile(msgFileName);

        MapiContact contact2 = (MapiContact)msg.ToMapiMessageItem();
        Assert.IsTrue(contact.NameInfo.DisplayName == contact2.NameInfo.DisplayName);
        Assert.IsTrue(contact.ElectronicAddresses.Email1.EmailAddress == contact2.ElectronicAddresses.Email1.EmailAddress);
        Assert.IsTrue(contact.ProfessionalInfo.CompanyName == contact2.ProfessionalInfo.CompanyName);
        Assert.IsTrue(contact.ProfessionalInfo.Title == contact2.ProfessionalInfo.Title);
        Assert.IsTrue(contact.PhysicalAddresses.WorkAddress.Address == contact2.PhysicalAddresses.WorkAddress.Address);
        Assert.IsTrue(contact.Telephones.BusinessTelephoneNumber == contact2.Telephones.BusinessTelephoneNumber);
        Assert.IsTrue(contact.Telephones.MobileTelephoneNumber == contact2.Telephones.MobileTelephoneNumber);

@Adnan.Ahmad ,
Thank you for providing sample code. I tried with your code,but I got this errorScreenshot (71).png (5.5 KB)
I don’t know what’s wrong with this.But just to let know, I tried myself with different code, and was able to extract those information.
Here is code that I tried.

MapiMessage message = MapiMessage.FromFile(msgPath);  
MapiPropertyCollection properties = message.NamedProperties;
            foreach (KeyValuePair<long, MapiProperty> prop in properties)
            {
                if (((prop.Value).Descriptor).CanonicalName != null)
                {
                    if (((prop.Value).Descriptor).CanonicalName == "PidLidEmail1DisplayName")
                    {
                        string email1 = prop.Value.ToString();
                        string descriptors = ((prop.Value).Descriptor).ToString();


                    }
                    if (((prop.Value).Descriptor).CanonicalName == "PidLidEmail1EmailAddress")
                    {
                        string emailA = prop.Value.ToString();
                    }
                    if (((prop.Value).Descriptor).CanonicalName == "PidLidInstantMessagingAddress")
                    {
                        string ADD = prop.Value.ToString();
                    }
                }

With this code, I was able to extract those fields. :blush::blush: Following the same pattern, I think we can extract Email2 and Email3 information as well

@alishasharma,

It’s good to know that things are rectified on your end. Please feel free to share if there is still an issue incurring on your end.