|
-
April 13th, 2010, 04:55 AM
#1
integrating outlook with java application
can anyone tell me how i can access MS outlook to book meetings and appointments through my java application?
-
April 13th, 2010, 06:53 AM
#2
Re: integrating outlook with java application
-
April 15th, 2010, 01:33 AM
#3
Re: integrating outlook with java application
i found this code ..... using java.mail.* api ....
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Properties;
import javax.activation.DataHandler;
import javax.activation.DataSource;
import javax.mail.Message;
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;
public class SendMailTest
{
public boolean send(String uniqueId, Date reviewDateStartTime,
String reviewLocation, int reviewDurationMnts, String from,
String to, String title, String reviewSubject,
String reviewDescription, String summary) throws Exception {
reviewDateStartTime = new Date();
String fromMail = from;
String toMail = to;
uniqueId = "123456";
reviewDescription = "testing only";
reviewSubject = "testing review subject";
title = "testing";
summary = "testing summary";
to="[email protected]";
reviewDurationMnts = 30;
reviewLocation="test location";
from=to;
String meetingStartTime = getReviewTime(reviewDateStartTime,
reviewDurationMnts, false);
String meetingEndTime = getReviewTime(reviewDateStartTime,
reviewDurationMnts, 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));
/*
* try { message .setRecipients( Message.RecipientType.CC,
* InternetAddress
* .parse("[email protected],[email protected],[email protected]")); }
* catch (Exception e) { System.out .println("No exception in
* parsing recipients addresses"); System.out.println(">> Error: " +
* e.getMessage()); }
*/
message.setSubject(reviewSubject);
message.setHeader("X-Mailer", "test-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:"
+ to + "\n" + "ORGANIZER:MAILTO:" + from + "\n"
+ "DTSTART:" + meetingStartTime + "\n" + "DTEND:"
+ meetingEndTime + "\n" + "LOCATION:"
+ reviewLocation + "\n" + "TRANSP:OPAQUE\n"
+ "SEQUENCE:0\n" + "UID:" + uniqueId
+ "@iquest.com\n" + "DTSTAMP:" + meetingEndTime
+ "\n" + "CATEGORIES:Meeting\n" + "DESCRIPTION:"
+ reviewDescription + ".\n\n" + "SUMMARY:"
+ summary + "\n" + "PRIORITY:1\n"
+ "CLASS:PUBLIC\n" + "BEGIN:VALARM\n"
+ "TRIGGER:PT1440M\n" + "ACTION ISPLAY\n"
+ "DESCRIPTION:Reminder\n" + "END:VALARM\n"
+ "END:VEVENT\n" + "END:VCALENDAR");
messageBodyPart.setFileName("TestMeeting.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 me) {
me.printStackTrace();
}
return false;
}
public String getReviewTime(Date reviewDateTime, int rDuration, boolean flag) {
Calendar c = Calendar.getInstance();
SimpleDateFormat s = new SimpleDateFormat("yyyyMMdd");
c.setTime(reviewDateTime);
if (flag == true) {
c.add(Calendar.MINUTE, rDuration);
}
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;
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";
}
}
}
-
April 15th, 2010, 08:50 AM
#4
Re: integrating outlook with java application
can someone tell me how can i update a task .... only using java code ...
-
April 15th, 2010, 10:41 AM
#5
Re: integrating outlook with java application
i found this code ..... using java.mail.* api ..
Firstly, are you sure you have the legal right to post someone elses code on a public forum without any reference to the author?
Secondly, posting a load of code is pointless unless you:
- Explain what it does.
- Explain what you want it to do
- Use code tags to maintain the formatting.
-
April 15th, 2010, 01:45 PM
#6
Re: integrating outlook with java application
ok .. i got the point .
this is the first time i m using a forum .
i got the above posted code from a public site .
the above code is used to send a meeting request to MS outlook with the specified date and time and the recipient can accept or reject the request . when the recipient accepts the request the task appears on their calender but when the request is rejected theres no response to the java application.
My requirement is blocking the calender of MS outlook with a task that originates from my application.
and i seen a couple of connectors and api s like jintegra and moyosoft but they are not free.
is there any way to do it without these api s .
-
April 15th, 2010, 01:56 PM
#7
Re: integrating outlook with java application
Do you mean you don't want the recipient to have the option to accept or reject the meeting request, you just want to forcibly book time in their calendar?
-
April 17th, 2010, 10:55 PM
#8
Re: integrating outlook with java application
Yes exactly ... cause the recipient themselves will be booking the timeslot through my application.
-
April 19th, 2010, 10:57 AM
#9
Re: integrating outlook with java application
You need to search online to establish the format and available options of the mime message you are sending.
I've never done this with outlook but it is possibly as simple as changing the method type from a request to a send. For example change.
Code:
+ "PRODID:-//Microsoft Corporation//Outlook 9.0 MIMEDIR//EN\n"
+ "VERSION:2.0\n" + "METHOD:REQUEST\n"
...
to
Code:
+ "PRODID:-//Microsoft Corporation//Outlook 9.0 MIMEDIR//EN\n"
+ "VERSION:2.0\n" + "METHOD:SEND\n"
...
-
June 16th, 2012, 11:02 AM
#10
Re: integrating outlook with java application
 Originally Posted by drook
can someone tell me how can i update a task .... only using java code ...
Drook,
Were you able to find a solution to this problem ? - I have exactly the same requirements you had i.e recipients book timeslot through Java application and It need to appear in Outlook Calendar (without them taking action to Accept the Meeting as it is they who put the invite) - Please let me know - This would save a big effort for me!!!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|