Travailler avec MapiJournal dans un PST
Contents
[
Hide
]
Ajout de MapiJournal au PST
Créer un nouveau PST, ajouter des sous‑dossiers et des messages montrait comment créer un fichier PST et y ajouter un sous-dossier. Avec Aspose.Email, vous pouvez ajouter MapiJournal au sous-dossier Journal d’un fichier PST que vous avez créé ou chargé. Voici les étapes pour ajouter MapiJournal à un PST :
- Créez un MapiJournal objet.
- Définissez le MapiJournal propriétés à l’aide d’un constructeur et de méthodes.
- Créez un PST en utilisant le PersonalStorage.create() méthode.
- Créer un dossier prédéfini (Journals) à la racine du fichier PST en accédant au dossier racine puis en appelant le addMapiMessageItem() méthode.
Le fragment de code ci‑dessous montre comment créer un MapiJournal et l’ajouter ensuite au dossier Journal d’un fichier PST nouvellement créé.
// 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);
Ajout de pièces jointes à MapiJournal
Il est également possible d’ajouter des pièces jointes aux éléments du journal MAPI. Le code ci-dessous montre comment faire.
// 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");