Working with Appointments
Load and Save an Appointment in ICS Format
The Appointment class in Aspose.Email for Java can be used to load an appointment in ICS format as well as to create a new appointment and save it to a disk in ICS format. In this article, we first create an appointment and save it to a disk in ICS format and then we load it.
Load an Appointment in ICS Format
To load an appointment in ICS format, the following steps are required:
- Create an instance of the Appointment class.
- Call the Load() method by providing the path of the ICS file.
- Read any property to get any information from the appointment (ICS file).
The following code snippets show how to load an appointment in ICS format.
Create an Appointment and Save to Disk in ICS Format
The following steps are required to create an appointment and save it in ICS format.
- Create an instance of the Appointment class and initialize it with this constructor.
- Pass the following arguments in the above constructor
- Attendees
- Description
- End Date
- Location
- Organizer
- Start Date
- Summary
- Created Date
- Last Modified Date
- Call the Save() method and specify the file name and format in the arguments.
The appointment can be opened in Microsoft Outlook or any program that can load an ICS file. If the file is opened in Microsoft Outlook it automatically adds the appointment in the Outlook calendar.
The following code snippets show how to create and save an appointment to a disk in ICS format.
Saving Appointments to MSG Format
Aspose.Email makes it possible to save appointments directly to .msg files. The following public classes are available for customizing the saving process of apppointments:
- AppointmentMsgSaveOptions class with additional options to save appointments in msg format.
- AppointmentIcsSaveOptions class with additional options to save appointment in ics format. It was added to replace the obsolete IcsSaveOptions.
The code sample below shows how to load an appointment from a file, and then save it in two different formats: .ics and .msg.
Appointment appointment = Appointment.load("fileName");
appointment.save("fileName.ics", new AppointmentIcsSaveOptions());
appointment.save("fileName.msg", new AppointmentMsgSaveOptions());
Create an Appointment with HTML Content
It’s a common practice to use the X-ALT-DESC header in iCalendar (RFC 5545) format. It is an extended property that provides an alternative human-readable description of a calendar item or event. This header is often used to include a plain text or HTML representation of the event description, which can be useful for compatibility with older calendar software or for providing a simplified version of the description. In cases, when the primary description is not supported or displayed correctly by the recipient’s calendar application, X-ALT-DESC header is used to provide an alternative description of the event. It allows the sender to include different representations of the event description to ensure better compatibility and accessibility across different calendar software and platforms. To create an appointment with HTML content, set the HtmlDescription property to ‘true’. Try the following code sample that demonstrates how to create and define an appointment object with specific details and settings, including the date, time, location, organizer, attendees, and a formatted description:
Date startDate = new Date();
Appointment appointment = new Appointment("Bygget 83",
startDate, // start date
addHours(startDate, 1), // end date
new MailAddress("TintinStrom@from.com", "Tintin Strom"), // organizer
MailAddressCollection.to_MailAddressCollection(
new MailAddress("AinaMartensson@to.com", "Aina Martensson"))); // attendee
appointment.setHtmlDescription("<html>\n"
+ " <style type=\"\"text/css\"\">\n"
+ " .text {\n"
+ " font-family:'Comic Sans MS';\n"
+ " font-size:16px;\n"
+ " }\n"
+ " </style>\n"
+ " <body>\n"
+ " <p class=\"\"text\"\">Hi, I'm happy to invite you to our party.</p>\n"
+ " </body>\n"
+ " </html>");
Create a Draft Appointment Request
In order to save an appointment in a draft mode, the Method property of the Appointment class should be set to Publish. The following code sample demonstrates the use of this property as an example.
Draft Appointment Creation from Text
Adding and Removing Attachments from Calendar Items
Aspose.Email provides an attachments collection that can be used to add and retrieve attachments associated with calendar items. This article shows how to:
- Create and add attachments to an Appointment class object.
- Retrieve attachments information from an appointment.
- Extract attachments from an appointment.
Formatting Appointments
The programming samples below demonstrate how to use the AppointmentFormattingOptions class to format text and HTML.
Programming Sample - Text Formatting
Programming Sample - HTML Formatting
Read Multiple Events from ICS File
Write Multiple Events from ICS File
Set Participants Status of Appointment Attendees
Aspose.Email for .NET API lets you set status of appointment attendees while formulating a reply message. This adds the PARTSTAT property to the ICS file.
Customize Product Identifier for ICalendar
Aspose.Email for Java API allows to get or set the product identifier that created iCalendar object.
How to get around Address Validation when trying to Load Appointments
Aspose.Email for Java API allows to get around the email validation error by setting the IgnoreSmtpAddressCheck option on the AppointmentLoadOptions object and passing it in to the load call.
AppointmentLoadOptions lo = new AppointmentLoadOptions();
lo.setIgnoreSmtpAddressCheck(true);
Appointment appointment = Appointment.load("app.ics", lo);