CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 10 of 10
  1. #1
    Join Date
    Mar 2010
    Posts
    6

    integrating outlook with java application

    can anyone tell me how i can access MS outlook to book meetings and appointments through my java application?

  2. #2
    Join Date
    May 2006
    Location
    UK
    Posts
    4,473

    Re: integrating outlook with java application

    Try this
    Posting code? Use code tags like this: [code]...Your code here...[/code]
    Click here for examples of Java Code

  3. #3
    Join Date
    Mar 2010
    Posts
    6

    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="abcdef@xyz.com";
    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("a111@xyz.com.com,a222@xyz.com,a333@xyz.com")); }
    * 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" + "ACTIONISPLAY\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";
    }
    }

    }

  4. #4
    Join Date
    Mar 2010
    Posts
    6

    Re: integrating outlook with java application

    can someone tell me how can i update a task .... only using java code ...

  5. #5
    Join Date
    May 2006
    Location
    UK
    Posts
    4,473

    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:
    1. Explain what it does.
    2. Explain what you want it to do
    3. Use code tags to maintain the formatting.
    Posting code? Use code tags like this: [code]...Your code here...[/code]
    Click here for examples of Java Code

  6. #6
    Join Date
    Mar 2010
    Posts
    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 .

  7. #7
    Join Date
    May 2006
    Location
    UK
    Posts
    4,473

    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?
    Posting code? Use code tags like this: [code]...Your code here...[/code]
    Click here for examples of Java Code

  8. #8
    Join Date
    Mar 2010
    Posts
    6

    Re: integrating outlook with java application

    Yes exactly ... cause the recipient themselves will be booking the timeslot through my application.

  9. #9
    Join Date
    May 2006
    Location
    UK
    Posts
    4,473

    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"
    ...
    Posting code? Use code tags like this: [code]...Your code here...[/code]
    Click here for examples of Java Code

  10. #10
    Join Date
    Jun 2012
    Posts
    1

    Re: integrating outlook with java application

    Quote Originally Posted by drook View Post
    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!!!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



HTML5 Development Center

Click Here to Expand Forum to Full Width