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.
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java
String dataDir = "data/";
Date startTime = new Date();
Date endTime = new Date(startTime.getTime() + 60L * 60 * 1000);
MapiJournal journal = new MapiJournal("daily record", "called out in the dark", "Phone call", "Phone call");
journal.setStartTime(startTime);
journal.setEndTime(endTime);
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.
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java
String dataDir = "data/";
Date startTime = new Date();
Date endTime = new Date(startTime.getTime() + 60L * 60 * 1000);
MapiJournal journal = new MapiJournal("daily record", "called out in the dark", "Phone call", "Phone call");
journal.setStartTime(startTime);
journal.setEndTime(endTime);
// Add the companies information
journal.setCompanies(new String[] { "Company 1", "Company 2", "Company 3" });
// Add the attachments
for (String name : new String[] { "1.png", "Invitation.doc", "logo.jpg" }) {
// Read the attachment content into a byte array
byte[] data = Files.readAllBytes(Paths.get(dataDir + name));
journal.getAttachments().add(name, data);
}
// Save the journal item as an MSG file
journal.save(dataDir + "JournalWithAttachments_out.msg");