Managing Outlook MAPI Tasks in PST Files
Contents
[
Hide
]
Add Outlook MAPI Tasks to PST Files
Create New PST File and Add Subfolders demonstrates how to create a PST file and include subfolders within it. With Aspose.Email you can also add MAPI Tasks to the Tasks subfolder of a PST file that you have created or loaded. The code sample below demonstrates how to create and manage a task using the MapiTask class in an environment that supports manipulating personal storage table (PST) files. It defines a task with specific parameters and then saves this task to a PST file under a predefined “Tasks” folder.
- Create a MapiTask object setting the start date to the current date and the due date to three days from now.
- Set the task properties.
- Create a PST using the PersonalStorage.Create() method.
- Create a pre-defined folder (Tasks) at the root of the PST file by accessing the Root folder and then calling the add_mapi_message_item() method.
import datetime as dt
from aspose.email.mapi import MapiTask, MapiTaskHistory, MapiTaskOwnership
from aspose.email.storage.pst import PersonalStorage, FileFormatVersion, StandardIpmFolder
task = MapiTask("To Do", "Just click and type to add a new task",
dt.datetime.now(), dt.datetime.now() + dt.timedelta(days=3))
task.percent_complete = 20
task.estimated_effort = 2000
task.actual_effort = 20
task.history = MapiTaskHistory.ASSIGNED
task.last_update = dt.datetime.now()
task.users.owner = "Darius"
task.users.last_assigner = "Harkness"
task.users.last_delegate = "Harkness"
task.users.ownership = MapiTaskOwnership.ASSIGNERS_COPY
with PersonalStorage.create(data_dir + "AddMapiTaskToPST_out.pst", FileFormatVersion.UNICODE) as pst:
tasks_folder = pst.create_predefined_folder("Tasks", StandardIpmFolder.TASKS)
tasks_folder.add_mapi_message_item(task)