How to create and send an update to an existing event using the uisng BiWeekly library and Java Mail API?

I use BiWeekly to create a VEVENT, and then send it using the Java Mail API . Everything works fine, but how can I create an update for an existing event, that is, when I get a VEVENT that is updated, it will not create a new event on the calendar, but it will update an existing event?

I tried to set the sequence as follows event.setSequence(2) , but this will not work. After receiving the Lotus Notes mail agent, Google Mail always creates a new event.

This is my code to create and dispatch an event:

 try { String from = "email@example.com"; String to = "email@example.com"; Properties prop = new Properties(); prop.setProperty("mail.transport.protocol", "smtp"); prop.setProperty("mail.host", "smtp.example.com"); prop.setProperty("mail.user", "email"); prop.setProperty("mail.password", ""); Session session = Session.getDefaultInstance(prop, null); // Define message MimeMessage message = new MimeMessage(session); message.addHeaderLine("method=REQUEST"); message.addHeaderLine("charset=UTF-8"); message.addHeaderLine("component=VEVENT"); message.setFrom(new InternetAddress(from)); message.addRecipient(Message.RecipientType.TO, new InternetAddress(to)); message.setSubject("Message Subject"); StringBuffer sb = new StringBuffer(); /*EVENT START*/ VEvent event = new VEvent(); event.setUid("ANATOLYTARNAVSKY123"); event.setDescription("Invitation Description"); event.setSummary("Invitation Description"); event.setOrganizer("anatolyt@gmail.com"); event.setLocation("room"); event.setSequence(sequence); Calendar start = Calendar.getInstance(); start.add(Calendar.HOUR_OF_DAY, sequence + 2); Calendar end = Calendar.getInstance(); end.add(Calendar.HOUR_OF_DAY, sequence + 2); event.setDateStart(start.getTime()); event.setDateEnd(end.getTime()); icals.addEvent(event); WriterChainText text = Biweekly.write(icals); String result = text.go(); System.out.println(result); /*EVENT END*/ StringBuffer buffer = sb.append(result); // Create the message part BodyPart messageBodyPart = new MimeBodyPart(); // Fill the message messageBodyPart.setHeader("Content-Class", "urn:content-classes:calendarmessage"); messageBodyPart.setHeader("Content-ID", "calendar_message"); messageBodyPart.setDataHandler(new DataHandler( new ByteArrayDataSource(buffer.toString(), "text/calendar")));// very important // Create a Multipart Multipart multipart = new MimeMultipart(); // Add part one multipart.addBodyPart(messageBodyPart); // Put parts in message message.setContent(multipart); // send message Transport.send(message); } catch (MessagingException me) { me.printStackTrace(); } catch (Exception ex) { ex.printStackTrace(); } 

Here I put iterations of the code that I use to send invitations :

Thanks in advance.

UPDATE 1 :

These are the first and second VEVENT generated by my code and the BiWeekly library:

CREATE EVENT-VEVENT DATA ONLY :

 BEGIN:VCALENDAR VERSION:2.0 PRODID:-//Michael Angstadt//biweekly 0.4.3//EN METHOD:REQUEST BEGIN:VEVENT DTSTAMP:20151113T100301Z UID:ANATOLYTARNAVSKY123 DESCRIPTION:Invitation Description SUMMARY:Invitation Description ORGANIZER:mailto:anatolyt@example.com LOCATION:room SEQUENCE:0 DTSTART:20151113T120301Z DTEND:20151113T120301Z END:VEVENT END:VCALENDAR 

UPDATE EVENT - ONLY FOR VEVENT :

 BEGIN:VCALENDAR VERSION:2.0 PRODID:-//Michael Angstadt//biweekly 0.4.3//EN METHOD:REQUEST BEGIN:VEVENT DTSTAMP:20151113T100333Z UID:ANATOLYTARNAVSKY123 DESCRIPTION:Invitation Description SUMMARY:Invitation Description ORGANIZER:mailto:anatolyt@example.com LOCATION:room SEQUENCE:1 DTSTART:20151113T130333Z DTEND:20151113T130333Z END:VEVENT END:VCALENDAR 

UPDATE 2 :

When I send the first and second invitations, I receive the following email:

enter image description here

The full original email content with the remote trace path due to some privacy issues here:

CREATE EVENT - FULL E-MAIL without routing part :

 Date: Sat, 14 Nov 2015 08:03:47 -0700 From: anatolyt@example.com To: anatolyt@gmail.com Message-ID: ***** Subject: Escape Room Invitation MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_Part_0_451111351.1447513426727" X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 15111415-0021-0000-0000-000004CDC424 method=REQUEST charset=UTF-8 component=VEVENT ------=_Part_0_451111351.1447513426727 Content-Type: text/calendar; charset=us-ascii Content-Transfer-Encoding: 7bit Content-Class: urn:content-classes:calendarmessage Content-ID: calendar_message BEGIN:VCALENDAR VERSION:2.0 PRODID:-//Michael Angstadt//biweekly 0.4.3//EN METHOD:REQUEST CALSCALE:GREGORIAN BEGIN:VEVENT DTSTAMP:20151114T150346Z UID:anatolyt@example.com STATUS:CONFIRMED DESCRIPTION:Invitation Description SUMMARY:Invitation Summary ORGANIZER:mailto:anatolyt@example.com LOCATION:Escape room TRANSP:OPAQUE CREATED:20151114T150346Z LAST-MODIFIED:20151114T150346Z SEQUENCE:0 DTSTART:20151114T170346Z DTEND:20151114T170346Z END:VEVENT END:VCALENDAR ------=_Part_0_451111351.1447513426727-- 

UPDATE EVENT - FULL E-MAIL without routing part :

 Date: Sat, 14 Nov 2015 08:05:06 -0700 From: anatolyt@example.com To: anatolyt@gmail.com Message-ID: ***** Subject: Escape Room Invitation MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_Part_0_451111351.1447513506015" X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 15111415-0029-0000-0000-000004D409DF method=REQUEST charset=UTF-8 component=VEVENT ------=_Part_0_451111351.1447513506015 Content-Type: text/calendar; charset=us-ascii Content-Transfer-Encoding: 7bit Content-Class: urn:content-classes:calendarmessage Content-ID: calendar_message BEGIN:VCALENDAR VERSION:2.0 PRODID:-//Michael Angstadt//biweekly 0.4.3//EN METHOD:REQUEST CALSCALE:GREGORIAN BEGIN:VEVENT DTSTAMP:20151114T150505Z UID:anatolyt@example.com STATUS:CONFIRMED DESCRIPTION:Invitation Description SUMMARY:Invitation Summary ORGANIZER:mailto:anatolyt@example.com LOCATION:Escape room TRANSP:OPAQUE CREATED:20151114T150505Z LAST-MODIFIED:20151114T150505Z SEQUENCE:1 DTSTART:20151114T180505Z DTEND:20151114T180505Z END:VEVENT END:VCALENDAR ------=_Part_0_451111351.1447513506015-- 

UPDATE 3 It appears to be working correctly in Lotus Notes, but Google Calendar still does not recognize the update event.

UPDATE 4 - DECISION

As @arnudq wrote, I skipped the ATTENDEE property to make Google Calendar recognize the update event. Here is an example of how to do this:

  VEvent event = new VEvent(); ... Attendee attendee = new Attendee("Anatoly Tarnavsky", "anatolyt@gmail.com"); attendee.setRsvp(true); attendee.setRole(Role.CHAIR); attendee.setParticipationStatus(ParticipationStatus.CONFIRMED); ... event.setProperty(attendee); 
+3
google-calendar javamail icalendar rfc2445 ical4j
Nov 12 '15 at 15:56
source share
2 answers

Your code does not explicitly specify a UID property. As a result, the library is probably creating a new one for you.

The UID property is what identifies this VEVENT among others. As a result, your update must contain the same UID as the original event sent earlier.

You also lack at least one ATTENDEE property. One of ATTENDEE must have the value specified as mailto uri corresponding to the gmail email address that receives the invitation.

+4
Nov 13 '15 at 8:02
source share

Try adding the LAST-MODIFIED property to the VEVENT component. You seem to be doing the rest right - keeping the UID consistent and increasing SEQUENCE.

+3
Nov 14 '15 at 14:22
source share



All Articles