Working with MapiJournal in PST

Adding MapiJournal to PST

Create a New PST File and Add Subfolders showed how to create a PST file and add a subfolder to it. With Aspose.Email you can add MapiJournal to hte Journal subfolder of a PST file that you have created or loaded. Below are the steps to add MapiJournal to a PST:

  1. Create a MapiJournal object
  2. Set the MapiJournal properties using a constructor and methods.
  3. Create a PST using the PersonalStorage.create() method.
  4. Create a pre-defined folder (Journals) at the root of the PST file by accessing the root folder and then calling the add_mapi_message_item() method.

The following code snippet shows you 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-python-dotnet
journal =MapiJournal("daily record", "called out in the dark", "Phone call", "Phone call")
journal.start_time = dt.datetime.now();
journal.end_time = dt.datetime.today() + timedelta(hours=1)
personalStorage = PersonalStorage.create(dataDir + "CreateNewMapiJournalAndAddToPST_out.pst", FileFormatVersion.UNICODE)
tasksFolder = personalStorage.create_predefined_folder("Journal", StandardIpmFolder.JOURNAL)
tasksFolder.add_mapi_message_item(journal)
personalStorage.dispose()

Adding Attachments to MapiJournal

The following code snippet shows you how to add attachments to MapiJournal.

import os
from datetime import datetime, timedelta
from aspose.email.mapi import MapiJournal

data_dir = "path_to_data_directory"
attach_file_names = [os.path.join(data_dir, "Desert.jpg"), os.path.join(data_dir, "download.png")]

journal = MapiJournal("testJournal", "This is a test journal", "Phone call", "Phone call")
journal.start_time = datetime.now()
journal.end_time = journal.start_time + timedelta(hours=1)
journal.companies = ["company 1", "company 2", "company 3"]

for attach in attach_file_names:
    journal.attachments.append(attach, open(attach, 'rb').read())

journal.save(os.path.join(data_dir, "AddAttachmentsToMapiJournal_out.msg"))