Managing Outlook Tasks
Creating, Saving and Reading Tasks
Aspose.Email allows you to create Outlook tasks and save them in MSG format. The MapiTask class provides a number of properties such as percent_complete, estimated_effort, actual_effort, history, last_update, and others, to accommodate and set information required for an Outlook task. This article shows how to create, save and read a MapiTask from disk.
Create and Save Tasks to Disk
The code sample below demonstrates how to create, configure, and store an Outlook task using the MAPI (Messaging Application Programming Interface):
- Instantiate a new object of the MapiTask class.
- Configure task properties.
- Save the task to disk in MSG format.
import datetime as dt
from aspose.email.storage.pst import MapiSensitivity
from aspose.email.mapi import (MapiTask, MapiTaskHistory, MapiTaskOwnership,
MapiTaskStatus, TaskSaveFormat)
task = MapiTask("To Do", "Just click and type to add a new task",
dt.datetime(2026, 6, 1, 21, 30, 0),
dt.datetime(2026, 6, 4, 21, 30, 0))
task.percent_complete = 20
task.estimated_effort = 2000
task.actual_effort = 20
task.history = MapiTaskHistory.ASSIGNED
task.last_update = dt.datetime(2026, 6, 1, 21, 30, 0)
task.users.owner = "Darius"
task.users.last_assigner = "Harkness"
task.users.last_delegate = "Harkness"
task.users.delegator = "Test Delegator"
task.users.ownership = MapiTaskOwnership.ASSIGNERS_COPY
task.companies = ["company1", "company2", "company3"]
task.categories = ["category1", "category2", "category3"]
task.mileage = "Some test mileage"
task.billing = "Test billing information"
task.sensitivity = MapiSensitivity.PERSONAL
task.status = MapiTaskStatus.COMPLETE
task.save(data_dir + "CreatingAndSavingOutlookTask_out.msg", TaskSaveFormat.MSG)
Read MapiTask
A task loaded from disk in MSG format is represented by a MapiMessage object. Cast the item returned by its to_mapi_message_item() method to MapiTask to access the task-specific properties. The following code snippet demonstrates how to read a MapiTask:
import aspose.pycore as pycore
from aspose.email.mapi import MapiMessage, MapiTask
message = MapiMessage.load(data_dir + "task.msg")
task = pycore.cast(MapiTask, message.to_mapi_message_item())
print("Subject:", task.subject)
print("Due date:", task.due_date)
print("Percent complete:", task.percent_complete)
Read VToDo Tasks
Google Tasks exported in iCalendar format as VToDo events can be loaded using the MapiTask class. The following code snippet shows you how to load and read a VToDo task:
import aspose.email as ae
data_dir = "path/to/data/directory"
task = ae.mapi.MapiTask.from_v_todo(data_dir + "VToDoTask.ics")
task.save(data_dir + "VToDo_out.msg", ae.mapi.TaskSaveFormat.MSG)
Add Reminders to MapiTasks
Similar to Microsoft Outlook, Aspose.Email can add reminder information to a MapiTask. The following code snippet shows you how this task can be performed with Aspose.Email for Python via .NET:
import datetime as dt
from aspose.email.mapi import MapiTask, TaskSaveFormat
task = MapiTask("To Do", "Just click and type to add a new task",
dt.datetime(2026, 6, 1, 21, 30, 0),
dt.datetime(2026, 6, 4, 21, 30, 0))
task.reminder_set = True
task.reminder_time = dt.datetime(2026, 6, 1, 21, 30, 0)
task.reminder_file_parameter = "file://Alarm01.wav"
task.save(data_dir + "AddReminderInformationToMapiTask_out.msg", TaskSaveFormat.MSG)
Add Attachments to MapiTasks
Use the add method of the MapiAttachmentCollection class to add an attachment to a MapiTask. The following code sample will help you with that:
import aspose.email as ae
import datetime as dt
task = ae.mapi.MapiTask("Task with attachment", "Test body of the task with an attachment", dt.datetime.now(), dt.datetime.now())
task.attachments.add("Attachment.txt", str.encode("attachment data"))
task.save("AddAttachmentsToMapiTask_out.msg", ae.mapi.TaskSaveFormat.MSG)
Add Recurrence to MapiTasks
Aspose.Email allows you to create a recurring task where the recurrence can be daily, weekly, monthly, or yearly. The following code snippet shows you how to create a task with different recurrence types:
import datetime as dt
from aspose.email.mapi import (MapiTask, MapiTaskState, TaskSaveFormat,
MapiCalendarDailyRecurrencePattern,
MapiCalendarWeeklyRecurrencePattern,
MapiCalendarMonthlyRecurrencePattern,
MapiCalendarRecurrencePatternType,
MapiCalendarRecurrenceEndType,
MapiCalendarDayOfWeek)
start_date = dt.datetime(2026, 4, 30, 10, 0, 0)
task = MapiTask("Recurring task", "Task body", start_date, dt.datetime(2026, 4, 30, 11, 0, 0))
task.state = MapiTaskState.NOT_ASSIGNED
# Daily recurrence
daily = MapiCalendarDailyRecurrencePattern()
daily.pattern_type = MapiCalendarRecurrencePatternType.DAY
daily.period = 1
daily.end_type = MapiCalendarRecurrenceEndType.NEVER_END
daily.occurrence_count = 0
task.recurrence = daily
task.save(data_dir + "TaskDaily_out.msg", TaskSaveFormat.MSG)
# Weekly recurrence
weekly = MapiCalendarWeeklyRecurrencePattern()
weekly.pattern_type = MapiCalendarRecurrencePatternType.WEEK
weekly.period = 1
weekly.day_of_week = MapiCalendarDayOfWeek.WEDNESDAY
weekly.end_type = MapiCalendarRecurrenceEndType.NEVER_END
weekly.occurrence_count = 0
task.recurrence = weekly
task.save(data_dir + "TaskWeekly_out.msg", TaskSaveFormat.MSG)
# Monthly recurrence
monthly = MapiCalendarMonthlyRecurrencePattern()
monthly.pattern_type = MapiCalendarRecurrencePatternType.MONTH
monthly.period = 1
monthly.day = 30
monthly.end_type = MapiCalendarRecurrenceEndType.NEVER_END
monthly.occurrence_count = 0
task.recurrence = monthly
task.save(data_dir + "TaskMonthly_out.msg", TaskSaveFormat.MSG)
# Yearly recurrence - a monthly pattern with a period of 12 months
yearly = MapiCalendarMonthlyRecurrencePattern()
yearly.pattern_type = MapiCalendarRecurrencePatternType.MONTH
yearly.period = 12
yearly.end_type = MapiCalendarRecurrenceEndType.END_AFTER_N_OCCURRENCES
yearly.occurrence_count = 10
task.recurrence = yearly
task.save(data_dir + "TaskYearly_out.msg", TaskSaveFormat.MSG)
Task Conversion
Convert Tasks to MHT
The following code sample demonstrates how to convert a task to MHT format specifying additional options for the MHT format when task-specific fields should be rendered (RENDER_TASK_FIELDS) and that the header information should be included (WRITE_HEADER). The mht_format_options property of the MhtSaveOptions class is used to define additional options when saving in MHTML format.
import aspose.email as ae
msg = ae.mapi.MapiMessage.load("MapiTask.msg")
opt = ae.SaveOptions.default_mhtml
opt.mht_format_options = ae.MhtFormatOptions.RENDER_TASK_FIELDS | ae.MhtFormatOptions.WRITE_HEADER
msg.save("MapiTask_out.mht", opt)
Convert MSG to HTML Preserving Task Fields
The RENDER_TASK_FIELDS value of the HtmlFormatOptions enumeration makes it possible to include the task fields into the header of the saved HTML file. The following code snippet shows how to preserve the task fields in the header when saving a message as HTML:
import aspose.email as ae
from aspose.email.mapi import MapiMessage
msg = MapiMessage.load("task.msg")
options = ae.HtmlSaveOptions()
options.html_format_options = ae.HtmlFormatOptions.WRITE_HEADER | ae.HtmlFormatOptions.RENDER_TASK_FIELDS
msg.save("task.html", options)