Managing Outlook MAPI Journal Entries in PST Files
Contents
[
Hide
]
Add MAPI Journal Entries to PST Files
Create a New PST File and Add Subfolders shows how to create a new PST file and add a subfolder to it. With Aspose.Email you can also create a new MAPI journal entry and add it to a PST file. The code sample below demonstrates how to create a journal entry, set its properties, and store it in a newly created PST file:
- Create MAPI Journal Entry: Instantiate a MapiJournal object with the subject, the body and the type.
- Set Journal Timing: Define the start time of the journal entry as the current datetime using
dt.datetime.now()and set the end time to one hour later usingdt.datetime.today() + timedelta(hours=1). - Create PST File: Use PersonalStorage.create to generate a new PST file with the UNICODE format.
- Create Journal Folder: Within the new PST file, create a predefined folder named “Journal” using create_predefined_folder with the
StandardIpmFolder.JOURNALparameter. - Add Journal Entry to Folder: Add the previously created MAPI journal entry to the “Journal” folder using add_mapi_message_item.
Add Attachments to MAPI Journal Entries in PST Files
The code sample below demonstrates how to create and save a MAPI journal item using the Aspose.Email library. The journal entry is related to a phone call and includes attachment files.
- Define Directory and Attachments:
data_dir: A variable that holds the path to the data directory where files and outputs will be stored.attach_file_names: A list containing the full path filenames of the attachments to be added to the journal.
- Create a MapiJournal Object:
- A MapiJournal object is created with the title “testJournal”. This journal entry is described as a “Phone call” in both the subject and type fields.
journal.start_timeis set to the current time usingdatetime.now().journal.end_timeis calculated by adding one hour to the start time usingtimedelta(hours=1).
- Set Companies Involved:
- The
journal.companiesattribute is updated with a list of companies involved in this journal entry.
- The
- Attach Files to the Journal:
- A loop iterates over each file in
attach_file_names. For each file, it appends the file to thejournal.attachmentsby reading the file content in binary mode.
- A loop iterates over each file in
- Save the MapiJournal:
- Finally, the journal entry is saved as a “.msg” file in the specified data directory.
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"))