Работа с MapiJournal в PST
Contents
[
Hide
]
Добавление MapiJournal в PST
Создание нового PST, добавление подпапок и сообщений показано, как создать файл PST и добавить к нему подпапку. С помощью Aspose.Email вы можете добавить MapiJournal в подпапку Journal файла PST, который вы создали или загрузили. Ниже приведены шаги для добавления MapiJournal в PST:
- Создайте объект MapiJournal.
- Установите свойства MapiJournal с использованием конструктора и методов.
- Создайте PST с помощью метода PersonalStorage.create() .
- Создайте предопределённую папку (Journals) в корне файла PST, получив доступ к корневой папке и затем вызвав метод addMapiMessageItem() .
Ниже приведён код, который показывает, как создать MapiJournal и затем добавить его в папку Journal вновь созданного файла PST.
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); |
Добавление вложений в MapiJournal
Также возможно добавление вложений в элементы журнала MAPI. Код ниже показывает, как это сделать.
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"); |