Hi,
we can register in a msg either a mail or a contact
i would like to know how can i detect the format of a msg ? mail or contact ?
and how can i get the contact information into a msg ? i would like to save the contact information in a vcard.
I would also save a vcard in a msg.. How can i do that ? an code exemple would help me.
thanks for your help
best regards
Marc
Hi Marc,
Thank you for your inquiry.
If you can elaborate your scenario further, I will be able to suggest you a solution for your need.
In reference to PST parsing, you can detect the type by looking into MessageInfo.MessageClass property. For a Contact, the property will hold “IPM.Contact” whereas for a message it would be “IPM.Note”.
Please find below the source code to retrieve the contact, then save it in VCard and MSG formats.
C#
// load the Outlook PST file
PersonalStorage pst = PersonalStorage.FromFile(@“C:\temp\outlook.pst”, false);
// Get the Root folder
FolderInfo root = pst.RootFolder;
//Get Contacts folder
FolderInfo contacts = root.GetSubFolder(“Contacts”);
// Loop through all the contacts in this folder
MessageInfoCollection messageInfoCollection = contacts.GetContents();
foreach (MessageInfo messageInfo in messageInfoCollection)
{
// Get the contact information into an instance of MapiContact
MapiContact contact = (MapiContact)pst.ExtractMessage(messageInfo).ToMapiMessageItem();
// Display some contents on screen
Console.WriteLine("Name: " + contact.NameInfo.DisplayName);
// Save the MapiContact in VCard format
contact.Save(@“C:\demo\Contacts” + contact.NameInfo.DisplayName + “.vcf”, ContactSaveFormat.VCard);
// Get the contact information into an instance of MapiMessage
MapiMessage message = pst.ExtractMessage(messageInfo);
// Save the MapiMessage in MSG format
message.Save(@“C:\demo\Contacts” + message.DisplayName + “.msg”);
}
Please feel free to write back.
Regards,