This technical tip enables Java developers to create, add & retrieve attachments from calendar items in Java Apps using Aspose.Email for Java. Aspose.Email lets developers manage attachments with email messages using the MailMessage and MapiMessage class. Microsoft Outlook allows you to add as well as retrieve attachments from calendar items, that is ICS. This article shows how the same can be achieved using Aspose.Email for Java for ICS files. 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 an appointment.
• Extract attachments from an appointment.
Sample Code for Adding and Retrieving Attachments from Calendar Items
Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
calendar.set(2012, Calendar.NOVEMBER, 1, 0, 0, 0);
Date startDate = calendar.getTime();
calendar.set(2012, Calendar.DECEMBER, 1);
Date endDate = calendar.getTime();
MailAddressCollection attendees = new MailAddressCollection();
attendees.add(new MailAddress("email@example.com", "Attendee"));
WeeklyRecurrencePattern expected = new WeeklyRecurrencePattern(3);
Appointment app = new Appointment("Appointment Location", "Appointment Summary", "Appointment Description",
new MailAddress("firstname.lastname@example.org", "Organizer"), attendees, expected);
//Attach a file from disc to this appointment
File file = new File("OutputXLS.xls");
FileInputStream fis = new FileInputStream(file);
Attachment att = new Attachment(fis, file.getName());
String savedFile = "appWithAttachments.ics";
Appointment app2 = Appointment.load(savedFile);
System.out.println("Total Attachments: " + app2.getAttachments().size());
for (int i=0; i< app2.getAttachments().size();i++)
att = app2.getAttachments().get(i);
//Save the attachment to disc
Overview: Aspose.Email for Java
Aspose.Email for Java is a Non-Graphical Java component that enables Java applications to read and write MS Outlook MSG files from within a Java application without using MS Outlook. It enables developers to create new MSG file from scratch, update an existing MSG file, read Outlook MSG file & get its properties like subject, body, recipients in to, cc and bcc, adding or removing attachment, sender information & MAPI properties. Aspose.Email can be used with Web as well as Desktop Application.
- Homepage of Aspose.Email for Java
Aspose.Email for Java