Read Outlook business card (.msg)

Hello,

I want to read an Outlook Business card .msg; I can read the values of Firstname, Lastname, email, Work Phone correcty, but not the values of Fax, mobile phone, …
First, I tried to use MapiContact but the Contact details was NULL

MapiContact contact = MapiContact.FromVCard(fileName);

So I used this code :

MapiMessage message = MapiMessage.FromFile(fileName);
// Get all named MAPI properties
MapiPropertyCollection properties = message.NamedProperties;
StringBuilder sb = new StringBuilder();
foreach (MapiNamedProperty mapiNamedProp in properties.Values)
{
    // Read any specific property
    string val = string.Format("{0} = {1}", mapiNamedProp.NameId, mapiNamedProp.GetString());
    sb.AppendLine(val);
}

Please how to get values of Fax, Mobile Phone,…

Regards

Hi Gafsi,


Thanks for writing to Aspose.Email support team.

Please give a try to the following code which extracts the required information from the contact message file and displays them.

MapiMessage message = MapiMessage.FromFile(“New Customer Full Name.msg”);
Console.WriteLine("Business 2 = " + message.Properties[MapiPropertyTag.PR_BUSINESS_TELEPHONE_NUMBER]);
Console.WriteLine("Business Fax = " + message.Properties[MapiPropertyTag.PR_BUSINESS_FAX_NUMBER]);
Console.WriteLine("Mobile No = " + message.Properties[MapiPropertyTag.PR_MOBILE_TELEPHONE_NUMBER]);

For your reference please use MapiPropertyTag to extract different type of properties from the MSG file.

Please feel free to write us back if you have any other query.

Hi Iqbal


I tried your code, The “values of business 2”, “business Fax” and “Mobile No” are empty although they are not in the business card.

Thanks for help

Hi Gafsi,


Give a try to the following code with the attached sample file. It displays the business fax number and mobile telephone number.

MapiMessage message = MapiMessage.FromFile(“EMAIL_436578\Kashif Iqbal.msg”);
Console.WriteLine("Business Fax = " + message.Properties[MapiPropertyTag.PR_BUSINESS_FAX_NUMBER_W]);
Console.WriteLine("Mobile No = " + message.Properties[MapiPropertyTag.PR_MOBILE_TELEPHONE_NUMBER_W]);

You may also please try the OutlookSpy plugin which displays all the property tags and their respective values in an Outlook item.

Feel free to write us if you have any other query as we will be more than happy to assist you as soon as possible.

Hi Iqbal,


Unfortunately, this example does not work for me, Please see the attached solution and tell me what can be the problem.

Regards.


Hi Gafsi,

I have analyzed the code and found that wrong properties are used in the code w.r.t sample msg file. There are two properties PR_BUSINESS_FAX_NUMBER_W and PR_MOBILE_TELEPHONE_NUMBER_W in the current sample msg file where as you are using properties which were sent with the previous example as given below:
PR_BUSINESS_TELEPHONE_NUMBER
PR_BUSINESS_FAX_NUMBER
PR_MOBILE_TELEPHONE_NUMBER

In order to use the sample msg file in your example code, please modify your code as given below:

//lblInfo.Text += "
Business 2 = " + message.Properties[MapiPropertyTag.PR_BUSINESS_TELEPHONE_NUMBER];

//blInfo.Text += "
Business Fax = " + message.Properties[MapiPropertyTag.PR_BUSINESS_FAX_NUMBER];

//lblInfo.Text += "
Mobile No = " + message.Properties[MapiPropertyTag.PR_MOBILE_TELEPHONE_NUMBER];


lblInfo.Text += "
Business Fax = " + message.Properties[MapiPropertyTag.PR_BUSINESS_FAX_NUMBER_W];
lblInfo.Text += "
Mobile No = " + message.Properties[MapiPropertyTag.PR_MOBILE_TELEPHONE_NUMBER_W];
For your kind reference it was suggested that Outlook Spy should be used for identifying the required properties from a msg file. When this software is installed, a menu option is added to your Outlook installation.as shown in attached screen shot MessageOpenedInOutlook.png.

When we open this OutlookSpy page, a button IMessage is displayed as shown in screen shot OutlookSpyOpened.PNG.

Finally we can identify the required properties from the list as shown in the screen shot PropertiesInOutlookSpy.PNG. The same properties are suggested to be used in the sample code.

I hope this explanation will be helpful for you to identify different properties from any msg file opened in the OutlookSpy.

If you have any other query please feel free to write us back.