Send calendar invite per email with java -
i'm trying send calendar invites per email java. recipient gets email instead of being shown invitation accept or decline, event automatically added calendar.
i'm building event/invite ical4j.jar
private calendar getinvite(session session) { calendar calendar = new calendar(); calendar.getproperties().add(version.version_2_0); calendar.getproperties().add(method.request); vevent event = new vevent( new datetime(sesion.getstartdate()), new datetime(sesion.getenddate()), session.getname()); event.getproperties().add(priority.medium); event.getproperties().add(clazz.public); try { uidgenerator ug = new uidgenerator("uidgen"); uid uid = ug.generateuid(); event.getproperties().add(uid); } catch (socketexception e) { // log things } (participant participant : session.getparticipants()) { attendee attendee = new attendee(uri.create("mailto:" + participant.getemail())); attendee.getparameters().add(role.opt_participant); attendee.getparameters().add(new cn(participant.getname())); attendee.getparameters().add(partstat.needs_action); event.getproperties().add(attendee); } calendar.getcomponents().add(event); return calendar; }
and how send email:
public void sendemail(string frommail, string tomail, string subject, string text, net.fortuna.ical4j.model.calendar calendar) { try { session session = session.getinstance(getmailproperties(), new javax.mail.authenticator() { protected passwordauthentication getpasswordauthentication() { return new passwordauthentication(getuser(), getpassword()); } }); mimemessage mimemessage = new mimemessage(session); mimemessage.setheader("content-transfer-encoding:", "7bit"); address address = new internetaddress(frommail); mimemessage.setfrom(address); mimemessage.setsentdate(calendar.getinstance().gettime()); mimemessage.setrecipients(message.recipienttype.to, tomail); mimemessage.setsubject(subject); calendar cal = calendar.getinstance(); mimemessage.setsentdate(cal.gettime()); multipart multipart = new mimemultipart("alternative"); // first part - html readable text mimebodypart msghtml = new mimebodypart(); msghtml.setcontent(text, "text/html; charset=utf-8"); multipart.addbodypart(msghtml); if (calendar != null) { // part calendar invite mimebodypart invite = new mimebodypart(); invite.setheader("content-class", "urn:content- classes:calendarmessage"); invite.setheader("content-id", "calendar_message"); invite.setheader("content-disposition", "inline"); invite.setcontent(calendar.tostring(), "text/calendar"); multipart.addbodypart(invite); } mimemessage.setcontent(multipart); transport.send(mimemessage); } catch (exception e) { // log things } }
but when email (in gmail), see no invitation, event automatically added calendar. can accept or decline clicking on event in calendar.
i have tried send invite, happens email ics attachment.
what missing?
you creating new calendar, that's why calendar added automatically. see documentation https://github.com/ical4j/ical4j/wiki/examples#creating_a_new_calendar try "creating meeting of 4 hour duration" , see if still have problem.
Comments
Post a Comment