First you whould add a MIME type in activation.jar and mail.jar called "text/calendar". It's quite simple, treat them like plain text.
in activation/META-INF/mimetypes.default add:
text/calendar ics ICS
and in mail/META-INF/mailcap add:
text/calendar;; x-java-content-handler=com.sun.mail.handlers.text_plain
/*
* EmailMeeting2.java
*
* Created on April 18, 2006, 10:12 AM
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package javamail;
import java.util.Properties;
import javax.mail.BodyPart;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Multipart;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart;
/**
*
* @author AshwinK
*/
public class EmailMeeting2 {
/** Creates a new instance of EmailMeeting2 */
public EmailMeeting2() {
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
try
{
EmailMeeting2 email = new EmailMeeting2();
email.send();
}
catch (Exception e)
{
e.printStackTrace();
}
}
public void send() throws Exception {
try {
String host = "server.interrait.com";
String from = "ashwink@interrait.com";
String to = "ashwink@interrait.com";
// Get system properties
Properties props = System.getProperties();
// Setup mail server
props.put("mail.smtp.host", host);
// Get session
Session session = Session.getInstance(props, 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.addRecipient(Message.RecipientType.TO, new InternetAddress(from));
message.setSubject("Outlook Meeting Request Using JavaMail");
StringBuffer sb = new StringBuffer();
StringBuffer buffer = sb.append("BEGIN:VCALENDAR\n"+
"PRODID:-//Microsoft Corporation//Outlook 9.0 MIMEDIR//EN\n"+
"VERSION:2.0\n"+
"METHOD:REQUEST\n"+
"BEGIN:VEVENT\n"+
"ATTENDEE;CN=\"SVGK, Raju (Raju)\";ROLE=REQ-PARTICIPANT;MAILTO:ashwink@interrait.com\n"+
"ATTENDEE;CN=\"SV, Raj (Raj)\";ROLE=OPT-PARTICIPANT;MAILTO:ashwink@interrait.com\n"+
"ORGANIZER:MAILTO:ashwink@interrait.com\n"+
"DTSTART:20050406T073000Z\n"+
"DTEND:20050406T080000Z\n"+
"LOCATION:conf\n"+
"TRANSP:OPAQUE\n"+
"SEQUENCE:0\n"+
"UID:040000008200E00074C5B7101A82E00800000000A0A742E5073AC5010000000000000000100\n"+
" 0000029606C073D82204AB6C77ACE6BC2FBE2\n"+
"DTSTAMP:20050405T122004Z\n"+
"CATEGORIES:Meeting\n"+
"DESCRIPTION:What are you doing?\n\n"+
"SUMMARY:How are you?\n"+
"PRIORITY:5\n"+
"CLASS:PUBLIC\n"+
"BEGIN:VALARM\n"+
"TRIGGER:PT1440M\n"+
"ACTION:DISPLAY\n"+
"DESCRIPTION:Reminder\n"+
"END:VALARM\n"+
"END:VEVENT\n"+
"END:VCALENDAR\n");
// Create the message part
BodyPart messageBodyPart = new MimeBodyPart();
messageBodyPart.setHeader("Content-Class", "urn:content-classes:calendarmessage");
messageBodyPart.setHeader("Content-ID","calendar_message");
messageBodyPart.setContent(buffer.toString(), "text/calendar");
// Fill the message
messageBodyPart.setText("You are requested to participlate in the review meeting.");
// Create a Multipart
Multipart multipart = new MimeMultipart();
// Add part one
multipart.addBodyPart(messageBodyPart);
// Part two is attachment
// Create second body part
messageBodyPart = new MimeBodyPart();
String filename = "How are you.ics";
messageBodyPart.setFileName(filename);
messageBodyPart.setContent(buffer.toString(), "text/plain");
// Add part two
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();
}
}
}
2 comments:
Thank you very much for an informative Article. I came across a Java email component by the name of Aspose.Email for Java . Could you please share your thoughts about it?
Hello,thank you for sharing this article.
I want to delete the event from the calendar when it has been cancelled .
Have you an idea please?
Post a Comment