title: How to send an iCal meeting request using Java Mail, and receive the response
body: <p>I'm trying to send an iCal to an outlook, using Java Mail Library, I've read already the <a href="https://stackoverflow.com/questions/461889/sending-outlook-meeting-requests-without-outlook">Question</a>, and I already have some sample code </p>
  
  <pre><code>public class SendMeetingRequest {
  
  String host = "" ;
  String port = "" ;
  String sender = "" ;
  
  public static SimpleDateFormat dateFormat = new SimpleDateFormat( "yyyyMMdd'T'HHmm'00'" ) ;
  public static SimpleDateFormat dateParser = new SimpleDateFormat( "dd-MM-yyyy HH:mm" ) ;
  
  public static void main(String[] args) throws Exception {
      SendMeetingRequest sender = new SendMeetingRequest() ;
  
      sender.sendInvitation( “LogicaCMG Inschrijf Site”
                           , new String[] { “robert&lt;dot&gt;willems&lt;dot&gt;of&lt;dot&gt;brilman&lt;at&gt;logicacmg&lt;dot&gt;com”
                                          }
                           , “Outlook Meeting Request Using JavaMail”
                           , dateParser.parse( “28-08-2006 18:00″ )
                           , dateParser.parse( “28-08-2006 21:00″ )
                           , “LIS-42″
                           , “Bar op scheveningen”
                           , “&lt;font color=\”Red\”&gt;Aanwezigheid verplicht!&lt;/font&gt;&lt;br&gt;We gaan lekker een biertje drinken met z’n allen.”
                           ) ;
  }
  
  
  void sendInvitation( String organizer
                     , String[] to
                     , String subject
                     , Date start
                     , Date end
                     , String invitationId
                     , String location
                     , String description
                     ) throws Exception {
  
      try {
          Properties prop = new Properties();
          prop.put(”mail.smtp.port”, port );
          prop.put(”mail.smtp.host”, host );
  
          Session session = Session.getDefaultInstance(prop);
          session.setDebug(true);
  
          // Define message
          MimeMessage message = new MimeMessage(session);
          message.setFrom(new InternetAddress(sender));
  
          // Set TO
          if( to != null &amp;&amp; ( to.length &gt; 0 ) ) {
              InternetAddress[] address = new InternetAddress[ to.length ] ;
  
              for( int i = 0; i &lt; to.length; i++ ) {
                  address[ i ] = new InternetAddress( to[ i ] ) ;
              }
  
              message.setRecipients( Message.RecipientType.TO, address ) ;
          }
  
          // Set subject
          message.setSubject(subject);
  
          // Create iCalendar message
          StringBuffer messageText = new StringBuffer();
          messageText.append("BEGIN:VCALENDAR\n" +
                             "PRODID:-//Microsoft Corporation//Outlook 9.0 MIMEDIR//EN\n" +
                             "VERSION:2.0\n" +
                             "METHOD:REQUEST\n" +
                                 "BEGIN:VEVENT\n" +
                                 "ORGANIZER:MAILTO:" ) ;
          messageText.append( organizer ) ;
          messageText.append( "\n" +
                              "DTSTART:");
          messageText.append( dateFormat.format( start ) ) ;
          messageText.append( "\n" +
                              "DTEND:" ) ;
          messageText.append( dateFormat.format( end ) ) ;
          messageText.append( "\n" +
                              "LOCATION:" ) ;
          messageText.append( location ) ;
          messageText.append( "\n" +
                               "UID:" ) ;
          messageText.append( invitationId ) ;
          messageText.append( "\n" +
                              "DTSTAMP:" ) ;
          messageText.append( dateFormat.format( new java.util.Date() ) ) ;
          messageText.append( "\n" +
                              "DESCRIPTION;ALTREP=\"CID:&lt;eventDescriptionHTML&gt;\”" ) ;
          messageText.append( “\n” +
                                      ”BEGIN:VALARM\n” +
                                      ”TRIGGER:-PT15M\n” +
                                      ”ACTION:DISPLAY\n” +
                                      ”DESCRIPTION:Reminder\n” +
                                      ”END:VALARM\n” +
                                 ”END:VEVENT\n” +
                             ”END:VCALENDAR”
                             ) ;
  
          Multipart mp = new MimeMultipart();
  
          MimeBodyPart meetingPart = new MimeBodyPart() ;
          meetingPart.setDataHandler( new DataHandler( new StringDataSource( messageText.toString(), “text/calendar”, “meetingRequest” ) ) ) ;
          mp.addBodyPart( meetingPart ) ;
  
          MimeBodyPart descriptionPart = new MimeBodyPart() ;
          descriptionPart.setDataHandler( new DataHandler( new StringDataSource( description, “text/html”, “eventDescription” ) ) ) ;
          descriptionPart.setContentID( “&lt;eventDescriptionHTML&gt;” ) ;
          mp.addBodyPart( descriptionPart ) ;
  
          message.setContent( mp ) ;
  
          // send message
          Transport.send(message);
  
      } catch (MessagingException me) {
          me.printStackTrace();
  
      } catch (Exception ex) {
          ex.printStackTrace();
  
      }
  }
  
  private static class StringDataSource implements DataSource {
      private String contents ;
      private String mimetype ;
      private String name ;
  
  
      public StringDataSource( String contents
                             , String mimetype
                             , String name
                             ) {
          this.contents = contents ;
          this.mimetype = mimetype ;
          this.name = name ;
      }
  
      public String getContentType() {
          return( mimetype ) ;
      }
  
      public String getName() {
          return( name ) ;
      }
  
      public InputStream getInputStream() {
          return( new StringBufferInputStream( contents ) ) ;
      }
  
      public OutputStream getOutputStream() {
          throw new IllegalAccessError( “This datasource cannot be written to” ) ;
      }
  } }
  </code></pre>
  
  <p>But its being sent as an attachment to the outlook 2007 and outlook 2003, and even If I click the attachment to view and accept, I don't receive the Answer, which is the purpose of the application to have a similar functionality like outlook.</p>
  
  <p>Is there any procedure I need to know of, or is it the Invitation ID that makes the thing rough?</p>