Click to See Complete Forum and Search --> : Sending MS Outlook Meeting Request


mailvidi
09-28-2006, 03:23 AM
Hi all,

Can someone please send me a working JAVA code that would send a Meeting Request to MS Outlook :confused: ?

I Badly need this ASAP ... :(

My id: mailvidi@gmail.com :D

Thank You,
Vidi ;)

mailvidi
03-07-2011, 06:42 PM
Did this by ourselves.. I've been getting so many emails abt this.. so here's the code after 5 years :D


public void send(String uniqueId, Date reviewDateTime) throws Exception

{

String from = "123@456.com";

String to = "456@456.com";

String meetingStartTime = getReviewTime(reviewDateTime, false);

String meetingEndTime = getReviewTime(reviewDateTime, true);

Properties prop = new Properties();

StringBuffer sb = new StringBuffer();

StringBuffer buffer = null;

Session session = Session.getDefaultInstance(prop, null);

Message message = new MimeMessage(session);



try {

prop.put("mail.smtp.host", "192.168.112.111");

prop.put("mail.smtp.port", "25");



// Define message

message.setFrom(new InternetAddress(from));

message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(to, false));

message.setRecipients(Message.RecipientType.CC, InternetAddress.parse("123@456.com,456@456.com,789@456.com"));

message.setSubject("This is the subject of the Meeting Request");

message.setHeader("X-Mailer", "iQuest-Mailer");



// Create the message part

MimeBodyPart messageBodyPart = new MimeBodyPart();

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;ROLE=REQ-PARTICIPANT;RSVP=TRUE:MAILTO:123@456.com\n"

+ "ORGANIZER:MAILTO:456@456.com\n"

+ "DTSTART:" + meetingStartTime + "\n"

+ "DTEND:" + meetingEndTime + "\n"

+ "LOCATION:Conference room\n"

+ "TRANSP:OPAQUE\n"

+ "SEQUENCE:0\n"

+ "UID:" + uniqueId + "@456.com\n"

+ "DTSTAMP:" + meetingEndTime + "\n"

+ "CATEGORIES:Meeting\n"

+ "DESCRIPTION:This the description of the meeting.\n\n"

+ "SUMMARY:Test meeting request\n" + "PRIORITY:1\n"

+ "CLASS:PUBLIC\n" + "BEGIN:VALARM\n"

+ "TRIGGER:PT1440M\n" + "ACTION:DISPLAY\n"

+ "DESCRIPTION:Reminder\n" + "END:VALARM\n"

+ "END:VEVENT\n" + "END:VCALENDAR");

messageBodyPart.setFileName("meeting.ics");

messageBodyPart.setDataHandler(new DataHandler(new ByteArrayDataSource(buffer.toString(), "text/iCalendar")));

messageBodyPart.setHeader("Content-Class","urn:content-classes:calendarmessage");

messageBodyPart.setHeader("Content-ID", "calendar_message");

Multipart multipart = new MimeMultipart();

multipart.addBodyPart(messageBodyPart);

message.setContent(multipart);

Transport.send(message);

}

catch (Exception e) {

e.printStackTrace();

}

}



public String getReviewTime(Date reviewDateTime, boolean flag)

{

Calendar c = Calendar.getInstance();

SimpleDateFormat s = new SimpleDateFormat("yyyyMMdd");

c.setTime(reviewDateTime);

if (flag)

c.add(Calendar.MINUTE, 30);

String hour = c.get(Calendar.HOUR_OF_DAY) < 10 ? "0"

+ c.get(Calendar.HOUR_OF_DAY) : ""

+ c.get(Calendar.HOUR_OF_DAY);

String min = c.get(Calendar.MINUTE) < 10 ? "0" + c.get(Calendar.MINUTE)

: "" + c.get(Calendar.MINUTE);

String sec = c.get(Calendar.SECOND) < 10 ? "0" + c.get(Calendar.SECOND)

: "" + c.get(Calendar.SECOND);



String date = s.format(new Date(c.getTimeInMillis()));

String dateTime = date + "T" + hour + min + sec + "Z";

return dateTime;

}



private class ByteArrayDataSource implements DataSource

{

private byte[] data; // data for mail message



private String type; // content type/mime type



ByteArrayDataSource(String data, String type)

{

try

{

// Assumption that the string contains only ascii

// characters ! Else just pass in a charset into this

// constructor and use it in getBytes()

this.data = data.getBytes("iso-8859-1");

}

catch (Exception e)

{

e.printStackTrace();

}

this.type = type;

}

// DataSource interface methods

public InputStream getInputStream() throws IOException

{

if (data == null)

throw new IOException("no data exception in ByteArrayDataSource");

return new ByteArrayInputStream(data);

}



public OutputStream getOutputStream() throws IOException

{

throw new IOException("illegal operation in ByteArrayDataSource");

}



public String getContentType()

{

return type;

}



public String getName()

{

return "dummy";

}

}


Regards,
Vidi