Managing Outlook MAPI Notes in PST Files

Add Outlook MAPI Notes 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 MAPI notes and store them in a PST file. The code sample below creates three MAPI notes of different characteristics, adds them to a PST file within a designated folder, and then safely closes the file.

  1. MapiNote objects are created setting the subject, body, color, and height and width, if necessary.
  2. A new PST file is created using PersonalStorage.create specifying the UNICODE format.
  3. Within the PST file, a predefined folder named “Tasks” is created to store the notes.
  4. Each of the MAPI notes (note1, note2, and note3) is added to the notesFolder using the add_mapi_message_item method. This process integrates the notes into the PST structure for storage.
from aspose.email.mapi import MapiNote, NoteColor
from aspose.email.storage.pst import PersonalStorage, FileFormatVersion, StandardIpmFolder

note1 = MapiNote()
note1.subject = "Yellow color note"
note1.body = "This is a yellow color note"

note2 = MapiNote()
note2.subject = "Pink color note"
note2.body = "This is a pink color note"
note2.color = NoteColor.PINK

note3 = MapiNote()
note3.subject = "Blue color note"
note3.body = "This is a blue color note"
note3.color = NoteColor.BLUE
note3.height = 500
note3.width = 500

with PersonalStorage.create(data_dir + "AddMapiNoteToPST_out.pst", FileFormatVersion.UNICODE) as pst:
    notes_folder = pst.create_predefined_folder("Notes", StandardIpmFolder.NOTES)
    notes_folder.add_mapi_message_item(note1)
    notes_folder.add_mapi_message_item(note2)
    notes_folder.add_mapi_message_item(note3)