Accessing Microsoft Outlook from Java

Java/J2EE COM Interoperability Products Page

This example demonstrates how to access Microsoft Outlook from Java. J-Integra® for COM is a Java interoperability component that bridges Java and Microsoft Outlook. It provides bi-directional access of Java objects and COM components.

We do not provide the documentation of the generated Java proxies since the Java proxies are just mapped from the programming API of the COM component. For more information about Microsoft Outlook programming, please refer to the Microsoft Outlook VBA Language Reference. The quickest way to start programming Java-to-Outlook is to find a VB example first, and then map the VB example to Java.

Refer to the Excel example for the details of steps.

/* This example is for Outlook XP and lists all the items in the outlook Journal folder.
 *
 * It assumes that the 'com2java' tool has been run on the Outlook type library
 * C:\Program Files\Microsoft Office\Office10\MSOUTL.OLB
 * and that the pure Java files that were generated are in a subdirectory called 'outlook'
 */

import com.linar.jintegra.AuthInfo;
import outlook.*;

public class OutlookExample {

  public static void main(java.lang.String[] args) {

    try {
      com.linar.jintegra.Log.logImmediately(3, "jintegra.log");

      // If running this Java client under MS windows then make sure the J-Integra® 'bin' directory
      // is in your PATH, otherwise run DCOMCNFG on the machine running Outlook (Start|Run|DCOMCNFG),
      // grant a specific user default launch and access permissions, and uncomment the following
      // line (specifying the appropriate domain/user/password)
      // com.linar.jintegra.AuthInfo.setDefault("NT DOMAIN", "NT USER", "NT PASSWORD");

      _Application app = new Application();
      System.out.println("Created the Application instance");

      _NameSpace namespace = app.getNamespace("MAPI");
      _Folders namespaceFolders = namespace.getFolders();
      MAPIFolder personalFolders = namespaceFolders.item("Mailbox - Raymond He");
      MAPIFolder journal = personalFolders.getFolders().item("Journal");
      _Items journalItems = journal.getItems();

      int jNumIterms = journalItems.getCount();
      if (jNumIterms > 0){
        for (int i = 1; i <= jNumIterms; i++) {
          JournalItem journalItem = new JournalItem(journalItems.item(new Integer(i)));
          System.out.println("Journal Item " + i + " subject: '" + journalItem.getSubject() + "'");
        }
      }
      else {
        System.out.println("No Journal Item Found");
      }
      app.quit();
    } catch (java.lang.Exception e) {
      e.printStackTrace();
    } finally {
      // Release all remote objects that haven't already been garbage collected.
      com.linar.jintegra.Cleaner.releaseAll();
    }
  }
}