Create, Add & Retrieve Email Attachments from Calendar Items in Java Apps

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.
//your code here... 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("", "Attendee")); WeeklyRecurrencePattern expected = new WeeklyRecurrencePattern(3); Appointment app = new Appointment("Appointment Location", "Appointment Summary", "Appointment Description", startDate, endDate, new MailAddress("", "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()); app.getAttachments().add(att); fis.close(); String savedFile = "appWithAttachments.ics";, AppointmentSaveFormat.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); System.out.println(att.getName()); //Save the attachment to disc; }


Language: Java | User: Sheraz Khan | Created: Apr 16, 2014 | Tags: Manage email attachments add attachments from calendar items retrieve attachments from calendar items Create & add attachments to Appointment Extract attachments from an appointment