Working with Outlook Calendar Items
Working with MapiCalendar
Aspose.Email’s MapiCalendar class provides methods and attributes to set various properties of a calendar item. This article provides code samples for:
- Working with MapiCalendar
- Setting Reminder with the Created Appointment
- Convert Appointment EML to MSG with HTML Body
Creating and Saving Calendar items
The following code snippet shows you how to create and save a calendar item in ICS format.
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
// The path to the File directory. | |
string dataDir = RunExamples.GetDataDir_Outlook(); | |
// Create the appointment | |
MapiCalendar calendar = new MapiCalendar( | |
"LAKE ARGYLE WA 6743", | |
"Appointment", | |
"This is a very important meeting :)", | |
new DateTime(2012, 10, 2, 13, 0, 0), | |
new DateTime(2012, 10, 2, 14, 0, 0)); | |
calendar.Save(dataDir + "CalendarItem_out.ics", AppointmentSaveFormat.Ics); |
Saving the Calendar item as MSG
The following code snippet shows you how to save the calendar item as MSG.
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
calendar.Save(dataDir + "CalendarItemAsMSG_out.Msg", AppointmentSaveFormat.Msg); |
Adding display reminder to a Calendar
The following code snippet shows you how to add a display reminder to a calendar.
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
// The path to the File directory. | |
string dataDir = RunExamples.GetDataDir_Outlook(); | |
// Create Appointment | |
Appointment app = new Appointment("Home", DateTime.Now.AddHours(1), DateTime.Now.AddHours(1), "organizer@domain.com", "attendee@gmail.com"); | |
MailMessage msg = new MailMessage(); | |
msg.AddAlternateView(app.RequestApointment()); | |
MapiMessage mapi = MapiMessage.FromMailMessage(msg); | |
MapiCalendar calendar = (MapiCalendar)mapi.ToMapiMessageItem(); | |
// Set calendar Properties | |
calendar.ReminderSet= true; | |
calendar.ReminderDelta = 45;//45 min before start of event | |
string savedFile = (dataDir + "calendarWithDisplayReminder.ics"); | |
calendar.Save(savedFile, AppointmentSaveFormat.Ics); |
Adding audio reminder to a Calendar
The following code snippet shows you how to add an audio reminder to a calendar.
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
// The path to the File directory. | |
string dataDir = RunExamples.GetDataDir_Outlook(); | |
Appointment app = new Appointment("Home", DateTime.Now.AddHours(1), DateTime.Now.AddHours(1), "organizer@domain.com", "attendee@gmail.com"); | |
MailMessage msg = new MailMessage(); | |
msg.AddAlternateView(app.RequestApointment()); | |
MapiMessage mapi = MapiMessage.FromMailMessage(msg); | |
MapiCalendar calendar = (MapiCalendar)mapi.ToMapiMessageItem(); | |
// Set calendar properties | |
calendar.ReminderSet = true; | |
calendar.ReminderDelta = 58;//58 min before start of event | |
calendar.ReminderFileParameter = dataDir + "Alarm01.wav"; | |
string savedFile = (dataDir + "calendarWithAudioReminder_out.ics"); | |
calendar.Save(savedFile, AppointmentSaveFormat.Ics); |
Add/Retrieve attachments from Calendar files
The following code snippet shows you how to add/retrieve attachments from calendar files.
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
string[] files = new string[3]; | |
files[0] = dataDir + "attachment_1.doc"; | |
files[1] = dataDir + "download.png"; | |
files[2] = dataDir + "Desert.jpg"; | |
Appointment app1 = new Appointment("Home", DateTime.Now.AddHours(1), DateTime.Now.AddHours(1), "organizer@domain.com", "attendee@gmail.com"); | |
foreach (string file in files) | |
{ | |
using (MemoryStream ms = new MemoryStream(File.ReadAllBytes(file))) | |
{ | |
app1.Attachments.Add(new Attachment(ms, Path.GetFileName(file))); | |
} | |
} | |
app1.Save(dataDir + "appWithAttachments_out.ics", AppointmentSaveFormat.Ics); | |
Appointment app2 = Appointment.Load(dataDir + "appWithAttachments_out.ics"); | |
Console.WriteLine(app2.Attachments.Count); | |
foreach (Attachment att in app2.Attachments) | |
Console.WriteLine(att.Name); |
Status of Recipients from a Meeting Request
The following code snippet shows you how to show the status of recipients from a meeting request.
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
MapiMessage message = MapiMessage.FromFile(fileName); | |
foreach (MapiRecipient recipient in message.Recipients) | |
{ | |
Console.WriteLine(recipient.RecipientTrackStatus); | |
} |
Create MapiCalendarTimeZone from Standard Timezone
The following code snippet shows you how to Create MapiCalendarTimeZone from standard Timezone.
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
MapiCalendarTimeZone timeZone = new MapiCalendarTimeZone(TimeZoneInfo.Local); |
Setting Reminder with the Created Appointment
A reminder can be added when an appointment is created. These alarms can trigger based on different criteria like n minutes before the schedule starts, repeat n times at n intervals. Different tags can be used to create these triggers in the script enclosed by BEGIN:VALARM and END:VALARM within an appointment. There is a number of variants in which the reminder can be set on an appointment.
Setting a Reminder by Adding Tags
The following code snippet shows you how to set a reminder by adding tags.
Convert Appointment EML to MSG with HTML Body
Since version 19.3, Aspose.Email provides the ability to convert Appointment EML to MSG while retaining the HTML body of the appointment. Aspose.Email provides a MapiConversionOptions.ForcedRtfBodyForAppointment property which has a default value of true. When the value of MapiConversionOptions.ForcedRtfBodyForAppointment is set to true, the appointment body is converted to RTF format. To keep the appointment body format in HTML format, set the value of MapiConversionOptions.ForcedRtfBodyForAppointment to false.
The following example demonstrates the use of MapiConversionOptions.ForcedRtfBodyForAppointment property to keep the appointment body format in HTML format.
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
// Outlook directory | |
string dataDir = RunExamples.GetDataDir_Outlook(); | |
MailMessage mailMessage = MailMessage.Load(dataDir + "TestAppointment.eml"); | |
MapiConversionOptions conversionOptions = new MapiConversionOptions(); | |
conversionOptions.Format = OutlookMessageFormat.Unicode; | |
// default value for ForcedRtfBodyForAppointment is true | |
conversionOptions.ForcedRtfBodyForAppointment = false; | |
MapiMessage mapiMessage = MapiMessage.FromMailMessage(mailMessage, conversionOptions); | |
Console.WriteLine("Body Type: " + mapiMessage.BodyType); | |
mapiMessage.Save(dataDir + "TestAppointment_out.msg"); |