Convert ICS to Other Formats

Convert ICS to EML

For a calendar event or appointment representation, Aspose.Email has the Appointment class. The following code sample demonstrates the process of ICS to EML conversion:

  1. Load the ICS file to be converted using the Appointment.load method.
  2. Create a new MailMessage object to hold the calendar data.
  3. Add the appointment from the ICS file to the EML as an alternate view using the requestApointment() method.
  4. Save the EML file with the converted data using the save method with EmlSaveOptions specifying the save type as EmlFormat.
// Load the ICS file to be converted
Appointment ics = Appointment.load("My File.ics");
// Create an EML
MailMessage eml = new MailMessage();
// Add the appointment to the EML
eml.addAlternateView(ics.requestApointment());
// Save the EML
eml.save("Saved File.eml", new EmlSaveOptions(MailMessageSaveType.getEmlFormat()));

Convert ICS to EMLX

To convert an ICS file to EMLX format, follow the instructions from the Convert ICS to EML section and save the .emlx file as shown in the following line of code:

Appointment ics = Appointment.load("My File.ics");
MailMessage eml = new MailMessage();
eml.addAlternateView(ics.requestApointment());

// Save as an EMLX
eml.save("Saved File.emlx", new EmlSaveOptions(MailMessageSaveType.getEmlxFormat()));

Convert ICS to HTML

The following code sample demonstrates the conversion process:

  1. Load the ICS file to be converted using the Appointment.load method.
  2. Create a new MailMessage object to hold the calendar data.
  3. Add the appointment from the ICS file to the EML as an alternate view using the requestApointment() method.
  4. Save the EML file with the converted data using the save method with HtmlSaveOptions to provide formatting options for the saved HTML file. In this specific case, HtmlFormatOptions.WriteHeader is used to include the HTML header in the output file, while HtmlFormatOptions.RenderCalendarEvent is used to render any calendar events contained in the EML message in a format suitable for display.
// Load the ICS file to be converted
Appointment ics = Appointment.load("My File.ics");
// Create an EML
MailMessage eml = new MailMessage();
// Add the appointment to the EML
eml.addAlternateView(ics.requestApointment());

// Save the EML as HTML
HtmlSaveOptions htmlSaveOptions = new HtmlSaveOptions();
htmlSaveOptions.setHtmlFormatOptions(HtmlFormatOptions.WriteHeader | HtmlFormatOptions.RenderCalendarEvent);
eml.save("Saved File.html", htmlSaveOptions);

Use other values of the HtmlFormatOptions enumeration and properties of the HtmlSaveOptions class to set format options as required.

Convert ICS to MBOX

The following code sample demonstrates the process of ICS to MBOX conversion. It loads an ICS file, creates an EML message, adds the appointment details from the ICS file to the EML message, and then writes the EML message to an MBOX storage file.

  1. Load the ICS file to be converted using the Appointment.load method.
  2. Create a new MailMessage object to hold the calendar data.
  3. Add the appointment from the ICS file to the EML as an alternate view using the requestApointment() method.
  4. Create a new MboxrdStorageWriter object.
  5. Add the EML message to the storage by writing the message content in MBOX format to the specified MBOX file.
// Load the ICS file to be converted
Appointment ics = Appointment.load("My File.ics");
// Create an EML
MailMessage eml = new MailMessage();
// Add the appointment to the EML
eml.addAlternateView(ics.requestApointment());

// Create an MBOX storage and add the EML to it
try (MboxrdStorageWriter mboxStorage = new MboxrdStorageWriter("Saved File.mbox", new MboxSaveOptions())) {
    mboxStorage.writeMessage(eml);
}

Convert ICS to MHTML

The following code sample demonstrates all the steps of the conversion process:

  1. Load the ICS file to be converted using the Appointment.load method.
  2. Create a new MailMessage object to hold the converted data.
  3. Add the appointment from the ICS file to the EML as an alternate view using the requestApointment() method.
  4. Save the EML file with the converted data using the save method with MhtSaveOptions to provide saving options for the MHTML file. In this specific case, MhtFormatOptions.WriteHeader is used to include the email message header in the output file, while MhtFormatOptions.RenderCalendarEvent is used to render any calendar events contained in the EML message in a format suitable for display.
// Load the ICS file to be converted
Appointment ics = Appointment.load("My File.ics");
// Create an EML
MailMessage eml = new MailMessage();
// Add the appointment to the EML
eml.addAlternateView(ics.requestApointment());

// Save the EML as MHTML
MhtSaveOptions mhtSaveOptions = new MhtSaveOptions();
mhtSaveOptions.setMhtFormatOptions(MhtFormatOptions.WriteHeader | MhtFormatOptions.RenderCalendarEvent);
eml.save("Saved File.mht", mhtSaveOptions);

This approach ensures that the converted MHTML file retains the calendar event details and formatting, enabling efficient sharing and viewing across various platforms and email clients.

Feel free to use other values of the MhtFormatOptions enumeration and properties of the MhtSaveOptions class to set format options as required.

Convert ICS to MSG

Converting ICS (iCalendar) files to MSG format is reasonable for better compatibility with Microsoft Outlook, as MSG files are commonly used for storing email messages, appointments, and other Outlook-related data. The following code sample demonstrates how to load an ICS file and save it as an MSG file without losing any data or formatting:

  1. Load the ICS file using Appointment.load and create an Appointment object from the calendar data stored in the file.
  2. Call the save method on the Appointment object to convert and save the loaded appointment data from the ICS file to an MSG file at the specified location.
// Load the ICS file to be converted and save it as an MSG
Appointment.load("My File.ics").save("Saved File.msg", AppointmentSaveFormat.Msg);

Convert ICS to OFT

The process involves loading ICS files and saving them as MSG files with further conversion to OFT format:

  1. Create a new stream object to store the appointment data in memory.
  2. Load the appointment data from the ICS file. Save the appointment data to the stream object in MSG format using the save() method.
  3. Load the appointment data from the stream by creating a new MapiMessage object using the MapiMessage.load() method.
  4. Save the loaded MapiMessage data as an Outlook template file using the save() method with the SaveOptions.getDefaultOft() format options.
// Load the ICS file to be converted and save it as an MSG into a stream
ByteArrayOutputStream msgStream = new ByteArrayOutputStream();
Appointment.load("My File.ics").save(msgStream, AppointmentSaveFormat.Msg);

// Save the MSG as an OFT
MapiMessage.load(new ByteArrayInputStream(msgStream.toByteArray()))
        .save("Saved File.oft", SaveOptions.getDefaultOft());

Convert ICS to OST

Aspose.Email provides functionality to load an ICS file, save it as an MSG file, then open an OST file, access calendar folders within the file, and easily add MSG files to the calendar folder:

  1. Create a stream to store the appointment data.
  2. Load the appointment data from an ICS file using the Appointment.load() method and save it to the stream in MSG format with the save method.
  3. Load the personal storage file using the fromFile method of the PersonalStorage class. Pass true as the second argument to open the storage for writing.
  4. Retrieve the calendar folder from the personal storage file with the getPredefinedFolder method.
  5. Use the addMessage method to add the appointment message to the calendar folder in the OST file.
// Load the ICS file to be converted and save it as an MSG into a stream
ByteArrayOutputStream msgStream = new ByteArrayOutputStream();
Appointment.load("My File.ics").save(msgStream, AppointmentSaveFormat.Msg);

// Open an OST file
try (PersonalStorage pst = PersonalStorage.fromFile("Saved File.ost", true)) {
    // Get the calendar folder
    FolderInfo calendarFolder = pst.getPredefinedFolder(StandardIpmFolder.Appointments);
    // Add the MSG to the calendar folder
    calendarFolder.addMessage(MapiMessage.load(new ByteArrayInputStream(msgStream.toByteArray())));
}

Convert ICS to PST

The following code sample demonstrates the conversion process:

  1. Create a stream to hold the appointment data.
  2. Load the appointment data from an ICS file using the Appointment.load() method and save it to the stream in MSG format with the save method.
  3. Create a new PST file with the file name using the PersonalStorage.create method.
  4. Create a calendar folder within the PST file to store appointments using the createPredefinedFolder method.
  5. Add the appointment message to the calendar folder within the PST file using the addMessage method.
// Load the ICS file to be converted and save it as an MSG into a stream
ByteArrayOutputStream msgStream = new ByteArrayOutputStream();
Appointment.load("My File.ics").save(msgStream, AppointmentSaveFormat.Msg);

// Create a PST file
try (PersonalStorage pst = PersonalStorage.create("Saved File.pst", FileFormatVersion.Unicode)) {
    // Create a calendar folder
    FolderInfo calendarFolder = pst.createPredefinedFolder("Calendar", StandardIpmFolder.Appointments);
    // Add the MSG to the calendar folder
    calendarFolder.addMessage(MapiMessage.load(new ByteArrayInputStream(msgStream.toByteArray())));
}