Working with MapiJournal in PST
Contents
[
Hide
]
Adding MapiJournal to PST
Create New PST, Add Sub-folders and Messages showed how to create a PST file and add a subfolder to it. With Aspose.Email you can add MapiJournal to the Journal subfolder of a PST file that you have created or loaded. Below are the steps to add MapiJournal to a PST:
- Create a MapiJournal object.
- Set the MapiJournal properties using a constructor and methods.
- Create a PST using the PersonalStorage.create() method.
- Create a pre-defined folder (Journals) at the root of the PST file by accessing the root folder and then calling the addMapiMessageItem() method.
The code snippet below shows how to create a MapiJournal and then add it to the Journal folder of a newly created PST file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
Date d1 = new Date(); | |
Calendar cl = Calendar.getInstance(); | |
cl.setTime(d1); | |
cl.add(Calendar.HOUR, 1); | |
Date d2 = cl.getTime(); | |
MapiJournal journal = new MapiJournal("daily record", "called out in the dark", "Phone call", "Phone call"); | |
journal.setStartTime(d1); | |
journal.setEndTime(d2); | |
PersonalStorage pst = PersonalStorage.create(dataDir + "JournalPST_out.pst", FileFormatVersion.Unicode); | |
FolderInfo journalFolder = pst.createPredefinedFolder("Journal", StandardIpmFolder.Journal); | |
journalFolder.addMapiMessageItem(journal); |
Adding Attachments to MapiJournal
It is also possible to add attachments to MAPI journal items. The code below shows how.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java | |
Date d1 = new Date(); | |
Calendar cl = Calendar.getInstance(); | |
cl.setTime(d1); | |
cl.add(Calendar.HOUR, 1); | |
Date d2 = cl.getTime(); | |
MapiJournal journal = new MapiJournal("daily record", "called out in the dark", "Phone call", "Phone call"); | |
journal.setStartTime(d1); | |
journal.setEndTime(d2); | |
//Add companies Information | |
String[] companies = { "Company 1", "Company 2", "Company 3" }; | |
journal.setCompanies(companies); | |
//Add attachments | |
String[] attachFileNames = new String[] { "1.png", "Invitation.doc", "logo.jpg" }; | |
for (String att : attachFileNames) { | |
//Load the attachment in a byte array | |
File file = new File(dataDir + att); | |
//FileInputStream fin = null; | |
//fin = new FileInputStream(file); | |
byte data[] = new byte[(int) file.length()]; | |
//Add the attachment to the Journal entry | |
journal.getAttachments().add(att, data); | |
} | |
//Save the Journal Item as MSG file | |
journal.save(dataDir + "JournalWithAttachments_out.msg"); |