Java Outlook Connector 2.0 Review
If you work with Java and need to access meetings, contacts, emails, etc from the users Outlook, you could have done it using Groovy and Scriptom. But to write Java code, instead of Groovy code, you can use Java Outlook Connector (JOC) from Moyosoft. JOC is basically a wrapper to COM for accessing Outlook. Once you have added JOC to your project and you have imported the JOC classes you can write code to read and write data to outlook. Here an example that reads your contacts and prints out the full name and company name for each contact…
[source:java]
// Get Outlook Application
Outlook outlook = new Outlook();
// Find default Contact folder
OutlookFolder contactFolder = outlook.getDefaultFolder(FolderType.CONTACTS);
// Iterate over the contact items in the default contact folder
for(ItemsIterator j = contactFolder.getItems().iterator(); j.hasNext(); ) {
OutlookItem item = (OutlookItem)j.next();
// Verify that the item is a contact
if(item.getType().isContact()) {
OutlookContact contact = (OutlookContact)item;
// Print some contact info
System.out.println(“Full Name; “+contact.getFullName());
System.out.println(“Company; “+contact.getCompanyName());
}
}
// Get contact subfolders
FoldersCollection contactFolders = contactFolder.getFolders();
for(FoldersIterator i = contactFolders.iterator(); i.hasNext(); ) {
OutlookFolder folder = (OutlookFolder)i.next();
for(ItemsIterator j = folder.getItems().iterator(); j.hasNext(); ) {
OutlookItem item = (OutlookItem)j.next();
if(item.getType().isContact()) {
OutlookContact contact = (OutlookContact)item;
// Print contact info
System.out.println(“Full Name; “+contact.getFullName());
System.out.println(“Company; “+contact.getCompanyName());
}
}
}
// Dispose the library
outlook.dispose();
[/source]
Here is another example that lists all folders (contact, meetings, inbox, etc) from Outlook in a neatly indented format. In this example I will create a function which will call itself recursively for subfolders.
[source:java]
public static void searchFolders(FoldersCollection folders, String indent) {
// Iterate over outlook foldres
for (FoldersIterator fi = folders.iterator(); fi.hasNext();) {
OutlookFolder folder = (OutlookFolder)fi.next();
// Print the folder name
System.out.println(indent+”Folder Name; “+folder.getName());
// Recursively search subfolders
searchFolders(folder.getFolders(), indent + ” “);
}
}
[/source]
To invoke the searchFolders method to actually print out all the folders in Outlook, I would use code like the following.
[source:java]
// Get Outlook Application
Outlook outlook = new Outlook();
searchFolders(outlook.getFolders(), “”);
// Dispose the library
outlook.dispose();
[/source]
Again, for the above example to work you need to add the joc and moyocore jars to your project. Once these jars have been added you can import them. All the code in these examples throw exceptions which has been omitted to keep the samples simple.
Java Outlook Connector has support for Outlook notes, meetings, mails, contacts and more. If you are a Java developer that has to write software solutions that integrate with Outlook, you might already have discovered the usefulness of Java Outlook Connector.
Technorati Tags: java, outlook, com, joc, moyosoft, scriptom, groovy