Advertisement
Guest User

Untitled

a guest
Mar 6th, 2019
452
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.93 KB | None | 0 0
  1. try {
  2. String from = "email@example.com";
  3. String to = "email@example.com";
  4. Properties prop = new Properties();
  5. prop.setProperty("mail.transport.protocol", "smtp");
  6. prop.setProperty("mail.host", "smtp.example.com");
  7. prop.setProperty("mail.user", "email");
  8. prop.setProperty("mail.password", "");
  9.  
  10. Session session = Session.getDefaultInstance(prop, null);
  11.  
  12. // Define message
  13. MimeMessage message = new MimeMessage(session);
  14. message.addHeaderLine("method=REQUEST");
  15. message.addHeaderLine("charset=UTF-8");
  16. message.addHeaderLine("component=VEVENT");
  17.  
  18. message.setFrom(new InternetAddress(from));
  19. message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
  20. message.setSubject("Message Subject");
  21.  
  22. StringBuffer sb = new StringBuffer();
  23.  
  24.  
  25. /*EVENT START*/
  26. VEvent event = new VEvent();
  27. event.setUid("ANATOLYTARNAVSKY123");
  28. event.setDescription("Invitation Description");
  29. event.setSummary("Invitation Description");
  30. event.setOrganizer("anatolyt@gmail.com");
  31. event.setLocation("room");
  32.  
  33. event.setSequence(sequence);
  34.  
  35.  
  36. Calendar start = Calendar.getInstance();
  37. start.add(Calendar.HOUR_OF_DAY, sequence + 2);
  38. Calendar end = Calendar.getInstance();
  39. end.add(Calendar.HOUR_OF_DAY, sequence + 2);
  40.  
  41. event.setDateStart(start.getTime());
  42. event.setDateEnd(end.getTime());
  43. icals.addEvent(event);
  44.  
  45. WriterChainText text = Biweekly.write(icals);
  46. String result = text.go();
  47.  
  48.  
  49. System.out.println(result);
  50. /*EVENT END*/
  51.  
  52. StringBuffer buffer = sb.append(result);
  53.  
  54.  
  55. // Create the message part
  56. BodyPart messageBodyPart = new MimeBodyPart();
  57.  
  58. // Fill the message
  59. messageBodyPart.setHeader("Content-Class", "urn:content-classes:calendarmessage");
  60. messageBodyPart.setHeader("Content-ID", "calendar_message");
  61. messageBodyPart.setDataHandler(new DataHandler( new ByteArrayDataSource(buffer.toString(), "text/calendar")));// very important
  62.  
  63. // Create a Multipart
  64. Multipart multipart = new MimeMultipart();
  65.  
  66. // Add part one
  67. multipart.addBodyPart(messageBodyPart);
  68.  
  69. // Put parts in message
  70. message.setContent(multipart);
  71.  
  72. // send message
  73. Transport.send(message);
  74. } catch (MessagingException me) {
  75. me.printStackTrace();
  76. } catch (Exception ex) {
  77. ex.printStackTrace();
  78. }
  79.  
  80. BEGIN:VCALENDAR
  81. VERSION:2.0
  82. PRODID:-//Michael Angstadt//biweekly 0.4.3//EN
  83. METHOD:REQUEST
  84. BEGIN:VEVENT
  85. DTSTAMP:20151113T100301Z
  86. UID:ANATOLYTARNAVSKY123
  87. DESCRIPTION:Invitation Description
  88. SUMMARY:Invitation Description
  89. ORGANIZER:mailto:anatolyt@example.com
  90. LOCATION:room
  91. SEQUENCE:0
  92. DTSTART:20151113T120301Z
  93. DTEND:20151113T120301Z
  94. END:VEVENT
  95. END:VCALENDAR
  96.  
  97. BEGIN:VCALENDAR
  98. VERSION:2.0
  99. PRODID:-//Michael Angstadt//biweekly 0.4.3//EN
  100. METHOD:REQUEST
  101. BEGIN:VEVENT
  102. DTSTAMP:20151113T100333Z
  103. UID:ANATOLYTARNAVSKY123
  104. DESCRIPTION:Invitation Description
  105. SUMMARY:Invitation Description
  106. ORGANIZER:mailto:anatolyt@example.com
  107. LOCATION:room
  108. SEQUENCE:1
  109. DTSTART:20151113T130333Z
  110. DTEND:20151113T130333Z
  111. END:VEVENT
  112. END:VCALENDAR
  113.  
  114. Date: Sat, 14 Nov 2015 08:03:47 -0700
  115. From: anatolyt@example.com
  116. To: anatolyt@gmail.com
  117. Message-ID: *****
  118. Subject: Escape Room Invitation
  119. MIME-Version: 1.0
  120. Content-Type: multipart/mixed;
  121. boundary="----=_Part_0_451111351.1447513426727"
  122. X-TM-AS-MML: disable
  123. X-Content-Scanned: Fidelis XPS MAILER
  124. x-cbid: 15111415-0021-0000-0000-000004CDC424
  125.  
  126. method=REQUEST
  127. charset=UTF-8
  128. component=VEVENT
  129.  
  130. ------=_Part_0_451111351.1447513426727
  131. Content-Type: text/calendar; charset=us-ascii
  132. Content-Transfer-Encoding: 7bit
  133. Content-Class: urn:content-classes:calendarmessage
  134. Content-ID: calendar_message
  135.  
  136. BEGIN:VCALENDAR
  137. VERSION:2.0
  138. PRODID:-//Michael Angstadt//biweekly 0.4.3//EN
  139. METHOD:REQUEST
  140. CALSCALE:GREGORIAN
  141. BEGIN:VEVENT
  142. DTSTAMP:20151114T150346Z
  143. UID:anatolyt@example.com
  144. STATUS:CONFIRMED
  145. DESCRIPTION:Invitation Description
  146. SUMMARY:Invitation Summary
  147. ORGANIZER:mailto:anatolyt@example.com
  148. LOCATION:Escape room
  149. TRANSP:OPAQUE
  150. CREATED:20151114T150346Z
  151. LAST-MODIFIED:20151114T150346Z
  152. SEQUENCE:0
  153. DTSTART:20151114T170346Z
  154. DTEND:20151114T170346Z
  155. END:VEVENT
  156. END:VCALENDAR
  157.  
  158. ------=_Part_0_451111351.1447513426727--
  159.  
  160. Date: Sat, 14 Nov 2015 08:05:06 -0700
  161. From: anatolyt@example.com
  162. To: anatolyt@gmail.com
  163. Message-ID: *****
  164. Subject: Escape Room Invitation
  165. MIME-Version: 1.0
  166. Content-Type: multipart/mixed;
  167. boundary="----=_Part_0_451111351.1447513506015"
  168. X-TM-AS-MML: disable
  169. X-Content-Scanned: Fidelis XPS MAILER
  170. x-cbid: 15111415-0029-0000-0000-000004D409DF
  171.  
  172. method=REQUEST
  173. charset=UTF-8
  174. component=VEVENT
  175.  
  176. ------=_Part_0_451111351.1447513506015
  177. Content-Type: text/calendar; charset=us-ascii
  178. Content-Transfer-Encoding: 7bit
  179. Content-Class: urn:content-classes:calendarmessage
  180. Content-ID: calendar_message
  181.  
  182. BEGIN:VCALENDAR
  183. VERSION:2.0
  184. PRODID:-//Michael Angstadt//biweekly 0.4.3//EN
  185. METHOD:REQUEST
  186. CALSCALE:GREGORIAN
  187. BEGIN:VEVENT
  188. DTSTAMP:20151114T150505Z
  189. UID:anatolyt@example.com
  190. STATUS:CONFIRMED
  191. DESCRIPTION:Invitation Description
  192. SUMMARY:Invitation Summary
  193. ORGANIZER:mailto:anatolyt@example.com
  194. LOCATION:Escape room
  195. TRANSP:OPAQUE
  196. CREATED:20151114T150505Z
  197. LAST-MODIFIED:20151114T150505Z
  198. SEQUENCE:1
  199. DTSTART:20151114T180505Z
  200. DTEND:20151114T180505Z
  201. END:VEVENT
  202. END:VCALENDAR
  203.  
  204. ------=_Part_0_451111351.1447513506015--
  205.  
  206. VEvent event = new VEvent();
  207. ...
  208. Attendee attendee = new Attendee("Anatoly Tarnavsky", "anatolyt@gmail.com");
  209. attendee.setRsvp(true);
  210. attendee.setRole(Role.CHAIR);
  211. attendee.setParticipationStatus(ParticipationStatus.CONFIRMED);
  212. ...
  213. event.setProperty(attendee);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement