We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Recurrence pattern is not working that is we are not able to set Daily - Weakly - Monthly - Yearly Recurrence pattern using Aspose.Email For Java API

Hello Aspose Team,


I have evaluated your latest version for Aspose.Email for Java API. It is working good for mails for me. But I have issue with "Recurrence pattern is not working that is we are not able to set Daily , Weakly , Monthly , Yearly Recurrence pattern ".

If you possible please send me your sample code. I have to create PST File with Calendars.




Thank You
Ajinath Kharade
p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; -webkit-text-stroke: #000000} span.s1 {font-kerning: none}

Hi Ajinath,


Thank you for posting your inquiry.

The following sample codes show working with Daily, Weekly, Monthly and Yearly recurrence patterns. Please have a look at these and let us know if you need to have any further information in this regard.

Daily Recurrences

java.util.Calendar calendar = java.util.Calendar.getInstance(java.util.TimeZone.getTimeZone(“GMT”));

calendar.set(2016, Calendar.DECEMBER, 22, 0, 0, 0);
Date startDate = calendar.getTime();

calendar.set(2016, java.util.Calendar.DECEMBER, 26, 0, 0, 0);
Date endDate = calendar.getTime();

MapiCalendar cal = new MapiCalendar(“location”,“Summary”, “Description”, startDate, endDate);

MapiCalendarDailyRecurrencePattern rec = new MapiCalendarDailyRecurrencePattern();
rec.setPatternType(MapiCalendarRecurrencePatternType.Day);
rec.setDayOfWeek(DayOfWeek.Sunday);
rec.setPeriod(1);
rec.setEndType(MapiCalendarRecurrenceEndType.EndAfterNOccurrences);
rec.setOccurrenceCount(getOccurrenceCount(cal.getStartDate(), cal.getEndDate(), “FREQ=DAILY”));

if (rec.getOccurrenceCount() ==0)
rec.setOccurrenceCount(1);

//Generate recurrence event from the defined recurrence
MapiCalendarEventRecurrence reccurrence = new MapiCalendarEventRecurrence();
reccurrence.setRecurrencePattern(rec);

cal.setRecurrence(reccurrence);

PersonalStorage pst = PersonalStorage.create(“DailyPst.pst”, FileFormatVersion.Unicode);

FolderInfo fi = pst.createPredefinedFolder(“CalPst”, StandardIpmFolder.Appointments);

fi.addMapiMessageItem(cal);

pst.dispose();

Weekly Recurrences

java.util.Calendar calendar = java.util.Calendar.getInstance(java.util.TimeZone.getTimeZone(“GMT”));

calendar.set(2016, java.util.Calendar.JULY, 16, 0, 0, 0);
Date startDate = calendar.getTime();

calendar.set(2016, java.util.Calendar.JULY, 16, 0, 0, 0);
Date dueDate = calendar.getTime();

calendar.set(2016, java.util.Calendar.SEPTEMBER, 1, 0, 0, 0);
Date endByDate = calendar.getTime();

MapiCalendar cal = new MapiCalendar(“In Aspose World”,“Summary”, “Description”, startDate, dueDate/!!!not endByDate!!!/);

MapiCalendarWeeklyRecurrencePattern rec = new MapiCalendarWeeklyRecurrencePattern();
rec.setPatternType(MapiCalendarRecurrencePatternType.Week);
rec.setEndType(MapiCalendarRecurrenceEndType.EndAfterNOccurrences);
rec.setPeriod(1);
rec.setWeekStartDay(DayOfWeek.Sunday);
rec.setDayOfWeek( MapiCalendarDayOfWeek.Friday);
rec.setOccurrenceCount(getOccurrenceCount(startDate, endByDate, “FREQ=WEEKLY;BYDAY=FR”));

if (rec.getOccurrenceCount() ==0)
rec.setOccurrenceCount(1);

//Generate recurrence event from the defined recurrence
MapiCalendarEventRecurrence reccurrence = new MapiCalendarEventRecurrence();
reccurrence.setRecurrencePattern(rec);
cal.setRecurrence(reccurrence);

PersonalStorage pst = PersonalStorage.create(“WeeklyPst.pst”, FileFormatVersion.Unicode);

FolderInfo fi = pst.createPredefinedFolder(“CalPst”, StandardIpmFolder.Appointments);

fi.addMapiMessageItem(cal);

pst.dispose();

Monthly Recurrences

java.util.Calendar calendar = java.util.Calendar.getInstance(java.util.TimeZone.getTimeZone(“GMT”));

calendar.set(2016, java.util.Calendar.JULY, 1, 0, 0, 0);
Date startDate = calendar.getTime();

calendar.set(2016, java.util.Calendar.JULY, 16, 0, 0, 0);
Date dueDate = calendar.getTime();

calendar.set(2016, java.util.Calendar.DECEMBER, 31, 0, 0, 0);
Date endByDate = calendar.getTime();

MapiCalendar cal = new MapiCalendar(“location”,“Summary”, “Description”, startDate, dueDate/!!!not endByDate!!!/);

// Set the Monthly recurrence
MapiCalendarMonthlyRecurrencePattern rec = new MapiCalendarMonthlyRecurrencePattern();
{
rec.setDay(15);
rec.setPeriod(1);
rec.setPatternType(MapiCalendarRecurrencePatternType.Month);
rec.setEndType(MapiCalendarRecurrenceEndType.EndAfterNOccurrences);
rec.setOccurrenceCount(getOccurrenceCount(startDate, endByDate, “FREQ=MONTHLY;BYMONTHDAY=15;INTERVAL=1”));
rec.setWeekStartDay(DayOfWeek.Monday);
};

if (rec.getOccurrenceCount() == 0)
{
rec.setOccurrenceCount(1);
}

//Generate recurrence event from the defined recurrence
MapiCalendarEventRecurrence reccurrence = new MapiCalendarEventRecurrence();
reccurrence.setRecurrencePattern(rec);

//now create mapi calendar and set its recurrence
cal.setRecurrence(reccurrence);

PersonalStorage pst = PersonalStorage.create(“MonthlyPst.pst”, FileFormatVersion.Unicode);

FolderInfo fi = pst.createPredefinedFolder(“CalPst”, StandardIpmFolder.Appointments);

fi.addMapiMessageItem(cal);

pst.dispose();

Yearly Recurrences

java.util.Calendar calendar = java.util.Calendar.getInstance(java.util.TimeZone.getTimeZone(“GMT”));

calendar.set(2016, Calendar.JULY, 1, 0, 0, 0);
Date startDate = calendar.getTime();

calendar.set(2016, java.util.Calendar.DECEMBER, 31, 0, 0, 0);
Date endByDate = calendar.getTime();

MapiCalendar cal = new MapiCalendar(“location”,“Summary”, “Description”, startDate, endByDate);

// Set the Yearly recurrence
MapiCalendarMonthlyRecurrencePattern rec = new MapiCalendarMonthlyRecurrencePattern();
{
rec.setDay(15);
rec.setPeriod(12);
rec.setPatternType(MapiCalendarRecurrencePatternType.Month);
rec.setEndType(MapiCalendarRecurrenceEndType.EndAfterNOccurrences);
rec.setOccurrenceCount(3);
};

//Generate recurrence event from the defined recurrence
MapiCalendarEventRecurrence reccurrence = new MapiCalendarEventRecurrence();
reccurrence.setRecurrencePattern(rec);

//now create mapi calendar and set its recurrence
cal.setRecurrence(reccurrence);

PersonalStorage pst = PersonalStorage.create(“YearlyPst.pst”, FileFormatVersion.Unicode);

FolderInfo fi = pst.createPredefinedFolder(“CalPst”, StandardIpmFolder.Appointments);

fi.addMapiMessageItem(cal);

pst.dispose();