Managing Recurrences
Aspose.Email supports the creation of MAPI recurrence patterns for calendar items and tasks. A pattern is assigned to the recurrence property of a MapiTask or a MapiCalendar object and is saved together with the item.
The following pattern classes are available:
| Class | Purpose |
|---|---|
| MapiCalendarDailyRecurrencePattern | Daily recurrences |
| MapiCalendarWeeklyRecurrencePattern | Weekly recurrences |
| MapiCalendarMonthlyRecurrencePattern | Monthly recurrences on a fixed day |
| MapiCalendarMonthlyNthRecurrencePattern | Monthly recurrences on the nth weekday |
| MapiCalendarYearlyAndMonthlyRecurrencePattern | Yearly recurrences |
Every pattern supports three end types provided by the MapiCalendarRecurrenceEndType enumeration:
END_AFTER_N_OCCURRENCES– the series ends after the given number of occurrences;END_AFTER_DATE– the series ends on the given date;NEVER_END– the series never ends.
Working with Daily Recurrences
In this type of recurrence the number of recurrences is set along with the other information:
- Set the start and the due dates.
- Create a MapiTask.
- Set the task state to
NOT_ASSIGNED. - Create the daily recurrence object and set its
pattern_type,period,end_typeandoccurrence_countproperties. - Assign the recurrence object to the
recurrenceproperty of the task. - Save the item to disk.
Daily Recurrences with Occurrence Count
import datetime
from aspose.email.mapi import (MapiTask, MapiTaskState, MapiCalendarDailyRecurrencePattern,
MapiCalendarRecurrencePatternType, MapiCalendarRecurrenceEndType,
TaskSaveFormat)
start_date = datetime.datetime(2025, 7, 16)
due_date = datetime.datetime(2025, 7, 16)
end_by_date = datetime.datetime(2025, 8, 1)
task = MapiTask("This is test task", "Sample Body", start_date, due_date)
task.state = MapiTaskState.NOT_ASSIGNED
# Set the daily recurrence
recurrence = MapiCalendarDailyRecurrencePattern()
recurrence.pattern_type = MapiCalendarRecurrencePatternType.DAY
recurrence.period = 1
recurrence.end_type = MapiCalendarRecurrenceEndType.END_AFTER_N_OCCURRENCES
recurrence.occurrence_count = 5
task.recurrence = recurrence
task.save("Daily_out.msg", TaskSaveFormat.MSG)
Daily Recurrences: END_AFTER_DATE End Type
The “End by” option is achieved by setting the end_date property. The period property defines the interval — every day, every second day, and so on.
import datetime
from aspose.email.mapi import (MapiCalendarDailyRecurrencePattern, MapiCalendarRecurrencePatternType,
MapiCalendarRecurrenceEndType)
end_by_date = datetime.datetime(2025, 8, 1)
# Every day until the end date
recurrence = MapiCalendarDailyRecurrencePattern()
recurrence.pattern_type = MapiCalendarRecurrencePatternType.DAY
recurrence.period = 1
recurrence.end_type = MapiCalendarRecurrenceEndType.END_AFTER_DATE
recurrence.end_date = end_by_date
# Every second day until the end date
recurrence = MapiCalendarDailyRecurrencePattern()
recurrence.pattern_type = MapiCalendarRecurrencePatternType.DAY
recurrence.period = 2
recurrence.end_type = MapiCalendarRecurrenceEndType.END_AFTER_DATE
recurrence.end_date = end_by_date
Daily Recurrences: NEVER_END End Type
from aspose.email.mapi import (MapiCalendarDailyRecurrencePattern, MapiCalendarRecurrencePatternType,
MapiCalendarRecurrenceEndType)
recurrence = MapiCalendarDailyRecurrencePattern()
recurrence.pattern_type = MapiCalendarRecurrencePatternType.DAY
recurrence.period = 1
recurrence.end_type = MapiCalendarRecurrenceEndType.NEVER_END
Working with Weekly Recurrences
Weekly recurrences are created with MapiCalendarWeeklyRecurrencePattern. The days of the week are selected through the day_of_week property using the values of the MapiCalendarDayOfWeek flag enumeration, which can be combined with the | operator.
Weekly Recurrences: END_AFTER_N_OCCURRENCES End Type
import datetime
from aspose.email.mapi import (MapiTask, MapiTaskState, MapiCalendarWeeklyRecurrencePattern,
MapiCalendarRecurrencePatternType, MapiCalendarRecurrenceEndType,
MapiCalendarDayOfWeek, TaskSaveFormat)
start_date = datetime.datetime(2025, 7, 16)
due_date = datetime.datetime(2025, 7, 16)
end_by_date = datetime.datetime(2025, 9, 1)
task = MapiTask("This is test task", "Sample Body", start_date, due_date)
task.state = MapiTaskState.NOT_ASSIGNED
recurrence = MapiCalendarWeeklyRecurrencePattern()
recurrence.pattern_type = MapiCalendarRecurrencePatternType.WEEK
recurrence.period = 1
recurrence.day_of_week = MapiCalendarDayOfWeek.FRIDAY
recurrence.end_type = MapiCalendarRecurrenceEndType.END_AFTER_N_OCCURRENCES
recurrence.occurrence_count = 7
task.recurrence = recurrence
task.save("Weekly_out.msg", TaskSaveFormat.MSG)
Selecting Multiple Days in a Week and Setting Intervals
from aspose.email.mapi import (MapiCalendarWeeklyRecurrencePattern, MapiCalendarRecurrencePatternType,
MapiCalendarRecurrenceEndType, MapiCalendarDayOfWeek)
recurrence = MapiCalendarWeeklyRecurrencePattern()
recurrence.pattern_type = MapiCalendarRecurrencePatternType.WEEK
recurrence.period = 2
recurrence.day_of_week = MapiCalendarDayOfWeek.FRIDAY | MapiCalendarDayOfWeek.MONDAY
recurrence.end_type = MapiCalendarRecurrenceEndType.END_AFTER_N_OCCURRENCES
recurrence.occurrence_count = 10
Weekly Recurrences: END_AFTER_DATE and NEVER_END End Types
import datetime
from aspose.email.mapi import (MapiCalendarWeeklyRecurrencePattern, MapiCalendarRecurrencePatternType,
MapiCalendarRecurrenceEndType, MapiCalendarDayOfWeek)
end_by_date = datetime.datetime(2025, 9, 1)
# End by a given date
recurrence = MapiCalendarWeeklyRecurrencePattern()
recurrence.pattern_type = MapiCalendarRecurrencePatternType.WEEK
recurrence.period = 1
recurrence.day_of_week = MapiCalendarDayOfWeek.FRIDAY
recurrence.end_type = MapiCalendarRecurrenceEndType.END_AFTER_DATE
recurrence.end_date = end_by_date
# Never end
recurrence = MapiCalendarWeeklyRecurrencePattern()
recurrence.pattern_type = MapiCalendarRecurrencePatternType.WEEK
recurrence.period = 1
recurrence.day_of_week = MapiCalendarDayOfWeek.FRIDAY
recurrence.end_type = MapiCalendarRecurrenceEndType.NEVER_END
Working with Monthly Recurrences
A monthly recurrence on a fixed day of the month is created with MapiCalendarMonthlyRecurrencePattern and its day property:
import datetime
from aspose.email.mapi import (MapiTask, MapiCalendarMonthlyRecurrencePattern,
MapiCalendarRecurrencePatternType, MapiCalendarRecurrenceEndType,
TaskSaveFormat)
start_date = datetime.datetime(2025, 7, 16)
due_date = datetime.datetime(2025, 7, 16)
task = MapiTask("This is test task", "Sample Body", start_date, due_date)
recurrence = MapiCalendarMonthlyRecurrencePattern()
recurrence.pattern_type = MapiCalendarRecurrencePatternType.MONTH
recurrence.period = 1
recurrence.day = 16
recurrence.end_type = MapiCalendarRecurrenceEndType.NEVER_END
task.recurrence = recurrence
task.save("Monthly_out.msg", TaskSaveFormat.MSG)
To repeat on the nth weekday of a month — the second Tuesday, for example — use MapiCalendarMonthlyNthRecurrencePattern with its day_of_week and position properties. The position is a value of the DayPosition enumeration — FIRST, SECOND, THIRD, FOURTH or LAST:
from aspose.email.mapi import (MapiCalendarMonthlyNthRecurrencePattern, MapiCalendarRecurrencePatternType,
MapiCalendarRecurrenceEndType, MapiCalendarDayOfWeek)
from aspose.email.calendar.recurrences import DayPosition
recurrence = MapiCalendarMonthlyNthRecurrencePattern()
recurrence.pattern_type = MapiCalendarRecurrencePatternType.MONTH_NTH
recurrence.period = 1
recurrence.day_of_week = MapiCalendarDayOfWeek.TUESDAY
recurrence.position = DayPosition.SECOND
recurrence.end_type = MapiCalendarRecurrenceEndType.NEVER_END
Working with Yearly Recurrences
Yearly recurrences are created with MapiCalendarYearlyAndMonthlyRecurrencePattern. A yearly period is expressed as 12 months:
import datetime
from aspose.email.mapi import (MapiTask, MapiCalendarYearlyAndMonthlyRecurrencePattern,
MapiCalendarRecurrencePatternType, MapiCalendarRecurrenceEndType,
TaskSaveFormat)
start_date = datetime.datetime(2025, 7, 16)
due_date = datetime.datetime(2025, 7, 16)
task = MapiTask("This is test task", "Sample Body", start_date, due_date)
recurrence = MapiCalendarYearlyAndMonthlyRecurrencePattern()
recurrence.pattern_type = MapiCalendarRecurrencePatternType.MONTH
recurrence.period = 12
recurrence.day = 16
recurrence.end_type = MapiCalendarRecurrenceEndType.NEVER_END
task.recurrence = recurrence
task.save("Yearly_out.msg", TaskSaveFormat.MSG)
WeekStartDay property that Aspose.Email for .NET exposes on the recurrence patterns is not available in Aspose.Email for Python via .NET. The week start day defaults to the value used by the pattern type.
See Also
- Managing Outlook Calendar Items — create, save and read MAPI calendar items.
- Managing Outlook Tasks — create and read MAPI tasks.