Tuesday, 15 February 2011

Java code to reschedule a outlook calendar event? -



Java code to reschedule a outlook calendar event? -

package necc.util.mail; import java.text.simpledateformat; import java.util.calendar; import java.util.date; import java.util.properties; import javax.activation.mailcapcommandmap; import javax.activation.mimetypesfiletypemap; import javax.mail.bodypart; import javax.mail.message; import javax.mail.messagingexception; import javax.mail.multipart; import javax.mail.session; import javax.mail.transport; import javax.mail.internet.internetaddress; import javax.mail.internet.mimebodypart; import javax.mail.internet.mimemessage; import javax.mail.internet.mimemultipart; public class emailmeeting { private static bodypart buildhtmltextpart() throws messagingexception { mimebodypart descriptionpart = new mimebodypart(); // note: if content spcified beingness text/html, outlook // won't read correctly tables @ // , properties div:s. thus, seek avoid fancy // content string content = "<font face=\\\"verdana\\\">necc tms estimation</font>"; descriptionpart.setcontent(content, "text/html; charset=utf-8"); homecoming descriptionpart; } // define somewhere icalendar date format private static simpledateformat icalendardateformat = new simpledateformat( "yyyymmdd't'hhmm'00'"); private static bodypart buildcalendarpart() throws exception { bodypart calendarpart = new mimebodypart(); calendar cal = calendar.getinstance(); cal.add(calendar.day_of_month, 1); cal.set(calendar.minute, 0); date start = cal.gettime(); cal.add(calendar.hour_of_day, 1); date end = cal.gettime(); // check icalendar spec in order build more complicated meeting // request string calendarcontent = "begin:vcalendar\n" + "method:request\n" + "prodid: bcp - meeting\n" + "version:2.0\n" + "begin:vevent\n" + "dtstamp:" + icalendardateformat.format(start) + "\n" + "dtstart:" + icalendardateformat.format(start) + "\n" + "dtend:" + icalendardateformat.format(end) + "\n" + "summary:necc tms estimation\n" + "uid:324\n" + "attendee;role=req-participant;partstat=needs-action;rsvp=true:mailto:abc_m@company.com\n" + "organizer:mailto:xyz_m@company.com\n" + "location:conference room\n" + "description:how can finish in estimated pd's?\n" + "sequence:0\n" + "priority:5\n" + "class:public\n" + "status:confirmed\n" + "transp:opaque\n" + "begin:valarm\n" + "action:display\n" + "description:reminder\n" + "trigger;related=start:-pt00h15m00s\n" + "end:valarm\n" + "end:vevent\n" + "end:vcalendar"; calendarpart.addheader("content-class", "urn:content-classes:calendarmessage"); calendarpart.setcontent(calendarcontent, "text/calendar;method=cancel"); homecoming calendarpart; } /* @param args */ public static void main(string[] args) throws exception { string host = "abc.abc.com";// hostname of mail service server string = "xyz@company.com"; // net address string = "abc@company.com"; // net address properties prop = new properties(); prop.put("mail.host", host); session session = session.getdefaultinstance(prop, null); // register text/calendar mime type mimetypesfiletypemap mimetypes = (mimetypesfiletypemap) mimetypesfiletypemap .getdefaultfiletypemap(); mimetypes.addmimetypes("text/calendar ics ics"); // register handling of text/calendar mime type mailcapcommandmap mailcap = (mailcapcommandmap) mailcapcommandmap .getdefaultcommandmap(); mailcap.addmailcap("text/calendar;; x-java-content-handler=com.sun.mail.handlers.text_plain"); mimemessage message = new mimemessage(session); message.setfrom(new internetaddress(from)); message.setsubject("necc tms"); message.addrecipient(message.recipienttype.to, new internetaddress(to)); // create alternative multipart multipart multipart = new mimemultipart("alternative"); // part 1, html text bodypart messagebodypart = buildhtmltextpart(); multipart.addbodypart(messagebodypart); // add together part two, calendar bodypart calendarpart = buildcalendarpart(); multipart.addbodypart(calendarpart, 0); // set multipart in message message.setcontent(multipart); // send message transport transport = session.gettransport("smtp"); transport.connect(); transport.sendmessage(message, message.getallrecipients()); transport.close(); system.out.println("email sent"); } }

sample code create calendar event. want send reschedule calendar event scheduled calendar. other alternative tried send cancellation mail service , 1 time again send new calendar event. required send 2 different mail. there way can in single mail.

the key to:

keep same uid in initial request bump sequence (and dtstamp)

i noticed in code that, although correctly setting method:request in icalendar stream, content-type still indicates method=cancel.

java outlook icalendar

No comments:

Post a Comment