Hi,
I’ve been trying to find a way to create a contacts folder (it’s not a standard messages folder) using Aspose Email for Java product, but I couldn’t do it.
Can you provide me a sample code for doing this task?
Thanks
You can add folders and sub-folders inside PST. Please visit this thread link for your kind reference.
Hi @mudassir.fayyaz,
I’m trying to create a contact folder but it’s not working, here is my code:
contactFolder = pst.getRootFolder().addSubFolder(“SampleFolder”, “ContactsClass”);
contactFolder.changeContainerClass(“IPF.Contacts”);
When I try to add a contact into this folder, I got the following error message:
MessageClass of the item to be added doesn’t supported.
Can you tell me what’s wrong with my code?
Thanks
Can you please provide a working sample code reproducing the issue on your end. I am also assuming that you are already using Aspose.Email for Java 20.9 on your end.
Hi @mudassir.fayyaz,
Here is my code for adding a contact into a folder:
InputStream stream = new ByteArrayInputStream(rawContactDecoded,0,rawContactDecoded.length);
MapiContact contact = MapiContact.fromVCard(stream);
contactFolder.addMapiMessageItem(contact);
Thanks
Can you please refer to this documentation section for your convenience. If there is still an issue then we need to have a working example along with vCard file that we may use on our end to verify the same.
The problem isn’t with the vCard file, it is on the folder class.
If I add the vCard to the standard “Contacts” folder, it works well. But I can’t create a contact folder and insert a vCard into it.
I request you to please provide the use case example that I may try on my end to further investigate the issue. Earlier, you have shared that issue is in adding contact inside calendar. I will appreciate if you may please provide a working example so that we may try to reproduce and help you further.
It’s not inside a calendar, it’s in contacts folder.
Please find bellow the full code:
contactFolder = pst.getRootFolder().addSubFolder(“SampleFolder”, “ContactsClass”);
contactFolder.changeContainerClass(“IPF.Contacts”);
InputStream stream = new ByteArrayInputStream(rawContactDecoded,0,rawContactDecoded.length);
MapiContact contact = MapiContact.fromVCard(stream);
contactFolder.addMapiMessageItem(contact);
Can you please try following alternate on your end.
FolderInfo tmpFolder = pst.createPredefinedFolder("Contacts", StandardIpmFolder.Contacts);
Dear @mudassir.fayyaz,
Using your sample code I can create the standard contacts folder, but this is not the question.
I would like to create another contacts folder to help me organize them.
Thanks
Can you please try using the following code without changeContainerClass.
contactFolder = pst.getRootFolder().addSubFolder("SampleFolder", "IPF.Contact");