title: Calendar events attached to email with java
body: <p>I've to create events on calendar using Java and I have two problem:</p>
  
  <ol>
  <li>The events is correcly viewed on smartphone and outlook, but on gmail from pc no events appear</li>
  <li>The timezone: how should I manage the time? I may have events in all the world, what time I have set for the events(UTC or the correct events date)?</li>
  </ol>
  
  <p>This is the code for email:</p>
  
  <pre><code>private void sendSimpleMessage(Mail mail) throws com.exception.MailException {
          try {
               JavaMailSender mailSender = mailConfig.getMailSender();
               MimeMessage message = mailSender.createMimeMessage();
  
               message.setFrom(new InternetAddress(mail.getFrom(), ""));
              message.setSubject(mail.getSubject());
              message.addRecipient(Message.RecipientType.TO, new InternetAddress(mail.getTo()));
  
           // Create an alternative Multipart
              Multipart multipart = new MimeMultipart("alternative");
  
              String mailContent = getContentFromTemplate(mail.getTemplate(),mail.getModel());
  
              BodyPart descriptionPart = new MimeBodyPart();
              descriptionPart.setContent(mailContent, "text/html; charset=utf-8");
              multipart.addBodyPart(descriptionPart);
  
              // Create the message part
              BodyPart messageBodyPart = new MimeBodyPart();
              // Fill the message
              messageBodyPart.setHeader("Content-Class", "urn:content-classes:calendarmessage");
              String iCalContent = getContentFromTemplate(TEMPLATE_CALENDAR_RESERVATION,mail.getModel());
  
              messageBodyPart.setContent(iCalContent, "text/calendar;method=CANCEL");
              multipart.addBodyPart(messageBodyPart);
  
              // Put parts in message
              message.setContent(multipart);
  
              mailSender.send(message);
  
          } catch (Throwable exception) {
              throw new com.exception.MailException(exception);
          }
      }
  </code></pre>
  
  <p>this is the event configuration (TEMPLATE_CALENDAR_RESERVATION):</p>
  
  <pre><code>BEGIN:VCALENDAR
  PRODID:-//Microsoft Corporation//Outlook 9.0 MIMEDIR//EN
  VERSION:2.0
  METHOD:REQUEST
  BEGIN:VEVENT
  ATTENDEE;ROLE=REQ-PARTICIPANT;RSVP=TRUE:MAILTO:${to}
  ORGANIZER:MAILTO:${from}
  DTSTART:${starDateString}
  DTEND:${endDateString}
  LOCATION:${room}
  TRANSP:OPAQUE
  SEQUENCE:0
  UID:${starDateString}${endDateString}${nowDateString}${from}${to}
  DTSTAMP:${nowDateString}
  CATEGORIES:Meeting
  DESCRIPTION:${subject}
  SUMMARY:${subject}
  PRIORITY:${priority}
  CLASS:PUBLIC
  BEGIN:VALARM
  ACTION:DISPLAY
  DESCRIPTION:Reminder
  END:VALARM
  END:VEVENT
  END:VCALENDAR
  </code></pre>
  
  <p>Thanks</p>