Working with Appointments

Load and Save Appointment in ICS Format

The Appointment class in Aspose.Email API can be used to load an appointment in ICS format as well as create a new appointment and save it to disk in ICS format. In this article, we first create an appointment and save it to disk in ICS format, and then we load it.

Create Appointment and Save to Disk in ICS Format

Following steps are required to create an appointment and save it in ICS format.

  1. Create an instance of the Appointment class and initialize it with this constructor.
  2. Pass the following arguments in the above constructor
    1. Attendees
    2. Description
    3. End Date
    4. Location
    5. Organizer
    6. Start Date
    7. Summary
  3. 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 shows you how to create and save an appointment to disk in ICS format.

For complete examples and data files, please go to https://github.com/aspose-email/aspose-email-python-dotnet
#Create Appointment instance
attendees = MailAddressCollection()
attendees.append("attendee@domain.com")
app = Appointment("Room 112", dt.datetime(2018, 5, 27, 22, 12, 11), dt.date(2018, 5, 28), "from@domain.com", attendees);
app.summary = "Release Meetting";
app.description = "Discuss for the next release"
app.save(dataDir + "AppointmentInICSFormat_out.ics", AppointmentSaveFormat.ICS)

Load Appointment ICS Format

To load an appointment in ICS format, the following steps are required:

  1. Create an instance of the Appointment class.
  2. Call the Load() method by providing the path of the ICS file.
  3. Read any property to get any information from the appointment (ICS file).

The following code snippets shows you how to load an appointment in ICS format.

For complete examples and data files, please go to https://github.com/aspose-email/aspose-email-python-dotnet
#Load Appointment instance
loadedAppointment = Appointment.load(dataDir + "AppointmentInICSFormat_out.ics")
print("Summary: " + loadedAppointment.summary)
print("Location: " + loadedAppointment.location)
print("Description: " + loadedAppointment.description)
print("Start date: " + str(loadedAppointment.start_date))
print("End date: " + str(loadedAppointment.end_date))
print("Organizer: " + loadedAppointment.organizer.address)
print("Attendees: " + loadedAppointment.attendees[0].address)

Read Multiple Events from ICS File

For complete examples and data files, please go to https://github.com/aspose-email/aspose-email-python-dotnet
#Load Appointment instance
reader = CalendarReader(dataDir + "US-Holidays.ics")
appointments = []
while reader.next_event():
appointments.append(reader.current)
print ("Total Appointments: " + str(len(appointments)))

Write Multiple Events to ICS File

For complete examples and data files, please go to https://github.com/aspose-email/aspose-email-python-dotnet
saveOptions = IcsSaveOptions()
saveOptions.action = AppointmentAction.CREATE
writer = CalendarWriter(dataDir + "WriteMultipleEventsToICS_out.ics", saveOptions)
attendees = MailAddressCollection()
attendees.append("attendee@domain.com")
for i in range(10):
app = Appointment("Room 112", dt.datetime(2018, 5, 27, 22, 12, 11), dt.date(2018, 5, 28), "from@domain.com", attendees)
app.description = "Test body " + str(i)
app.summary = "Test summary:" + str(i)
writer.write(app)

Create a Draft Appointment Request

It was shown in our earlier articles how to create and save an appointment in ICS format. It is often required to create an Appointment request in Draft mode, so as the basic information is added and then the same draft Appointment be forwarded to other users for necessary changes according to individual users. In order to save an Appointment in Draft mode, the Method property of Appointment class should be set to Publish. The following code snippet shows you how to create a draft appointment request.

For complete examples and data files, please go to https://github.com/aspose-email/aspose-email-python-dotnet
#Create Appointment instance
attendees = MailAddressCollection()
attendees.append("attendee@domain.com")
app = Appointment("Room 112", dt.datetime(2018, 5, 27, 22, 12, 11), dt.date(2018, 5, 28), "from@domain.com", attendees);
app.summary = "Release Meetting";
app.description = "Discuss for the next release"
app.method_type = AppointmentMethodType.PUBLISH
message = MailMessage("sender@domain.com", "recipient@domain.com", "", "")
message.add_alternate_view(app.request_apointment())
msg = MapiMessage.from_mail_message(message)
# Save the appointment as draft.
msg.save("DraftAppointmentRequest_out.msg")

Draft Appointment Creation from Text

The following code snippet shows you how to create a draft appointment from Text. 

For complete examples and data files, please go to https://github.com/aspose-email/aspose-email-python-dotnet
ical = """BEGIN:VCALENDAR
METHOD:PUBLISH
PRODID:-//Aspose Ltd//iCalender Builder (v3.0)//EN
VERSION:2.0
BEGIN:VEVENT
ATTENDEE;CN=test@gmail.com:mailto:test@gmail.com
DTSTART:20130220T171439
DTEND:20130220T174439
DTSTAMP:20130220T161439Z
END:VEVENT
END:VCALENDAR"""
sender = "test@gmail.com"
recipient = "test@email.com"
message = MailMessage(sender, recipient, "", "")
av = AlternateView.create_alternate_view_from_string(ical, ContentType("text/calendar"))
message.alternate_views.append(av)
msg = MapiMessage.from_mail_message(message)
msg.save(dataDir + "draft_out.msg")

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.

For complete examples and data files, please go to https://github.com/aspose-email/aspose-email-python-dotnet
location = "Room 5"
startDate = dt.datetime(2011, 12, 10, 10, 12, 11)
endDate = dt.date(2012, 11, 13)
organizer = ae.MailAddress("aaa@amail.com", "Organizer")
attendees = ae.MailAddressCollection()
attendee1 = ae.MailAddress("bbb@bmail.com", "First attendee")
attendee2 = ae.MailAddress("ccc@cmail.com", "Second attendee")
attendee1.participation_status = ae.ParticipationStatus.ACCEPTED
attendee2.participation_status = ae.ParticipationStatus.DECLINED
attendees.append(attendee1)
attendees.append(attendee2)
target2 = Appointment(location, startDate, endDate, organizer, attendees)