Lavorare con MapiJournal in PST

Aggiungere MapiJournal a PST

Crea un nuovo PST, aggiungi sottocartelle e messaggi mostrato come creare un file PST e aggiungere una sottocartella. Con Aspose.Email è possibile aggiungere MapiJournal alla sottocartella Journal di un file PST che hai creato o caricato. Di seguito i passaggi per aggiungere MapiJournal a un PST:

  1. Crea un MapiJournal oggetto.
  2. Imposta il MapiJournal proprietà usando un costruttore e metodi.
  3. Crea un PST usando il PersonalStorage.create() metodo.
  4. Crea una cartella predefinita (Journals) nella radice del file PST accedendo alla cartella radice e quindi chiamando il addMapiMessageItem() metodo.

Il frammento di codice seguente mostra come creare un MapiJournal e quindi aggiungerlo alla cartella Journal di un file PST appena creato.

// 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);

Aggiungere allegati a MapiJournal

È anche possibile aggiungere allegati agli elementi diario MAPI. Il codice sottostante mostra come.

// 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");