Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Help creating a Meeting Request for Outlook using JAVA

Reply
Thread Tools

Help creating a Meeting Request for Outlook using JAVA

 
 
al
Guest
Posts: n/a
 
      03-16-2007
I have been trying to figure out a way to create a meeting request
programmatically using JAVA Mail. So far I was able to create an email
and a meeting that goes out as an attachment, which users can open and
accept/decline and so forth.

I have not been able to send this as an actual meeting request. I want
it to work as if a meeting reminder that comes from Google Calendar
(if set up to send reminders to other emails that use Outlook) and
shows up on Outlook Calendar.

I have tried several things but no success. I have not modified the
code after doing several attempts to fix it, so it might have a lot of
redundant information.

Any Help would be appreciated...

Thanks!!


public class CalendarRequest {
public CalendarRequest() {
}

public static void main(String[] args) {
try {
CalendarRequest email = new CalendarRequest();
email.send();}
catch (Exception e) { e.printStackTrace(); }
}

public void send() throws Exception {
String host = "smtp.host.com";
String from = "(E-Mail Removed)";
String to = "(E-Mail Removed)";
Properties prop = new Properties();
// prop.put("mail.smtp.host", "mailhost"); -- format
prop.put("mail.smtp.host", host);


try {
Session session = Session.getDefaultInstance(prop, null);
// Define message
MimeMessage message = new MimeMessage(session);

message.addHeader("Mime-Version", "1.0");
message.addHeader("PRODID","-//Microsoft Corporation//Outlook 10.0
MIMEDIR//EN");
message.addHeader("version","2.0");
message.addHeader("method","REQUEST"); // Can be CANCEL to cancel
meeting
message.addHeader("charset","UTF-8");
message.addHeader("component","VEVENT");
message.setFrom(new InternetAddress(from));
message.addRecipient(Message.RecipientType.TO, new
InternetAddress(to));
message.setSubject("Outlook Meeting Request Using JavaMail");

StringBuffer sb ;
StringBuffer msg = CalendarRequest.EmailMessage();

// Microsoft
StringBuffer buffer = CalendarRequest.createMeetingText();

StringDataSource sdSource = new StringDataSource(buffer.toString(),
"text/calendar", "meetingRequest");

// Fill the message
MimeBodyPart meetingPart = new MimeBodyPart(); // for meeting
request
MimeBodyPart messageBody = new MimeBodyPart(); // for email message
MimeBodyPart attachmentBody = new MimeBodyPart(); // for
attachments

meetingPart.setDataHandler(new DataHandler(sdSource));
meetingPart.setContent("",sdSource.getContentType( ));
messageBody.setHeader("Content-Class","urn:content-
classes:calendarmessage");
messageBody.setHeader("Content-ID", "calendar_message");
messageBody.setContent(msg.toString(), "text/plain");


// Create a Multipart
Multipart multipart = new MimeMultipart();

// Add part one - meeting request - not working right now
multipart.addBodyPart(meetingPart); // adds the actual meeting
// add part two - actual email message
multipart.addBodyPart(messageBody); // add the email description

// Part three is attachment


String filename = "DCM Request.ics"; // need to change this later
attachmentBody.setFileName(filename);
attachmentBody.setContent(buffer.toString(), "text/plain");

// Add part two
multipart.addBodyPart(attachmentBody);

// Put parts in message
message.setContent(multipart);

// send message
Transport.send(message);

} catch (MessagingException me) {
me.printStackTrace();
} catch (Exception ex) {
ex.printStackTrace();
}
}

public static StringBuffer EmailMessage()
{
StringBuffer bf = new StringBuffer();
bf.append("Here is the line1 of email\n"
+ "Here is line2 of message\n"
+ "Create an HTML file instead"
);
return bf;
}

public static StringBuffer createMeetingText()
{
StringBuffer sb = new StringBuffer();
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:(E-Mail Removed)
\n"
+ "ORGANIZER:(E-Mail Removed)\n"
+ "DTSTART:20070316T053000Z\n"
+ "DTEND:20070316T060000Z\n"
+ "LOCATION:Conference room\n"
+ "TRANSP:OPAQUE\n"
+ "SEQUENCE:0\n"
+ "UID:
040000008200E00074C5B7101A82E00800000000002FF466CE 3AC5010000000000000000100\n"
+ " 000004377FE5C37984842BF9440448399EB02\n"
+ "DTSTAMP:20051206T120102Z\n"
+ "CATEGORIES:Meeting\n"
+ "DESCRIPTION:This the description of the meeting.\n\n"
+ "SUMMARY:Test meeting request\n" + "PRIORITY:5\n"
+ "CLASSUBLIC\n" + "BEGIN:VALARM\n"
+ "TRIGGERT1440M\n" + "ACTIONISPLAY\n"
+ "DESCRIPTION:Reminder\n" + "END:VALARM\n"
+ "END:VEVENT\n" + "END:VCALENDAR");

return sb;
}

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() {
InputStream is = null;
try {
is = new BufferedInputStream(new FileInputStream(
"c:\\temp\\tempfile.txt"));

} catch (Exception ex) {
System.out.println("Exception occured: " + ex.getMessage());
}
return is;

}

public OutputStream getOutputStream() {

ByteArrayOutputStream out = new ByteArrayOutputStream();
return out; // doing nothing - including error handling later...
}
}
}

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Outlook Meeting requests Through JAVA Vidya Java 1 01-11-2008 07:49 AM
Cisco Meeting Place Outlook 2000 Outlook 98 error ?? jmickler@cinci.rr.com Cisco 0 04-05-2006 12:23 PM
12/3/03 NYJavaSIG Meeting - Creating Dazzling Effects with Java Advanced Imaging Frank D. Greco Java 0 11-22-2003 04:03 PM
[MEETING] CORE Meeting Oct. 25th Daniel Berger Ruby 1 10-21-2003 05:37 AM
[MEETING] CORE Meeting August 9th Daniel Berger Ruby 0 08-01-2003 04:54 PM



Advertisments