Moyosoft Products | Services | Download | Contact us    
Java Outlook Connector
Products  >  Java Outlook Connector  >  Getting started    
Getting started
This page presents an introduction to the Java Outlook Connector product. You'll learn the basics on how to configure and use the library with your Java application.


You need three files to use the Java Outlook Connector with your application. The downloaded package contains a folder named « lib ». This folder contains the necessary files described in detail below:

      These files contains all Java classes.

      You have to add the JAR files to your application's CLASSPATH. The CLASSPATH is the path that the Java runtime environment (JRE) searches for classes and other resource files.

      There are multiple ways to setup the CLASSPATH depending on your development environment. For example, you can specify the path to the JAR files in the command line when launching your application using the « -cp » option:

      > java -cp lib\joc-v3.0.4-eval.jar;lib\moyocore.jar ...
      For more information about the CLASSPATH, have a look at Sun's documentation:

      This file contains all native code necessary to access the Outlook application. This file has to be accessible by the Java runtime environment (JRE) in order to load the library. By default, native libraries are searched in locations defined by the « java.library.path » system property. You can define this property when launching your Java application like this:

      > java -Djava.library.path=./lib ...
      You can also define the path to this DLL file at runtime using Java code: Use the static method Outlook.setLibraryPath(String path) before creating an instance of the Outlook object.

Using the library

To follow this guide, please have a look at the minimal sample application: The starting point is creating an Outlook object:
// Creating the Outlook application object
Outlook outlookApplication = new Outlook();
Once you created the Outlook object, you have access to Outlook's folders, items and data. As you can see in the example, to get the information about the currently logged-on user, the method Outlook.getCurrentUser() is used.

Look at the JavaDoc for the listing of all Outlook object's methods.

    Do not forget to call the method Outlook.dispose() when you're done using all Outlook objects. This is necessary to release native resources used by the library:

// Dispose the library
Outlook items are stored in folders. There is a Java class for each Outlook item type (contact, mail, appointment, etc.). The classes are organized in packages like this:

Now, let's have a look at a more complex sample application: This example displays all Outlook contacts stored in the default contacts' folder.

First of all, the default contacts' folder have to be loaded using the method Outlook.getDefaultFolder(FolderType) :

// Get the default contacts folder
OutlookFolder folder = outlookApplication.getDefaultFolder(FolderType.CONTACTS);
If the folder doesn't exist or some error occurs a ComponentObjectModelException is thrown. Otherwise, we can load and iterate through all the items in the contacts folder :

// Get the folder's items collection
ItemsCollection items = folder.getItems();

// Display info for all contacts in the folder
for(ItemsIterator it = items.iterator(); it.hasNext();)
   OutlookItem item = it.nextItem();

   // Check the item is a contact
   if(item != null && item.getType().isContact())
      OutlookContact contact = (OutlookContactitem;
      System.out.println("First name: " + contact.getFirstName());
      System.out.println("Last name: " + contact.getLastName());
      System.out.println("Company: " + contact.getCompanyName());
Items stored in an Outlook folder are always accessed through the ItemsCollection object. The ItemsCollection object allows you to:

For more information on how to perform each of these tasks, look at the example applications' source code.
    As you can see when iterating through all the items in the example, items contained in the collection can be of any type or even null in case of an unknown type.

For this reason the following test is necessary for each item to ensure it is a correct Contact item:

// Check the item is a contact
if(item != null && item.getType().isContact())
The same process is used for other items, like mails or appointments. First load the Outlook folder where the items are stored. Then access the items using the ItemsCollection object. Based on the item's type you can cast each item's object to a specific class. The table below shows the Java class to use for each item's type (OutlookItemType) :

    Item's typeJava class to use
    OutlookItemType.DISTRIBUTION_LIST   OutlookDistributionList

More information

Now you have the necessary knowledge to start building your Java application using our product. For more detailed information, look at: