Integrating a Lotus Notes application with Exchange

I recently finished a project with the purpose of integrating a Lotus Notes CRM application with Microsoft Outlook and Microsoft Exchange. The customer has moved their mail handling to Exchange and Outlook and still uses Lotus Notes for their application handling including this CRM application. The CRM application had functionality to import mails from Notes, send mail from Notes, and create and maintain meeting invitations. My task was to make this functionality work with Exchange and Outlook instead.

In order to integrate with Exchange I used the Exchange Web Services (EWS) Java API and created a Java class with the necessary jar files imported that is responsible for the interface between the existing Lotusscript logic and the EWS API. The Lotusscript logic then uses LS2J to use the methods in the Java class.

With Exchange Web Services installed on the Exchange server the Java API can access the web services using the WSDL at /EWS/Service.wsdl (through an endpoint called /EWS/exchange.asmx).

To allow the Lotus Notes client to communicate with the Exchange server I needed to change the java.policy file in order to add: permission java.net.NetPermission “setCookieHandler”, “write”;. To automate this I used this Lotusscript code by Darren Oliver that checks the java.policy file for a specific permission policy and if not found adds the permission policy.

At first I wanted to use Exchange Impersonation to allow a single Windows Active Directory account to be able to act on behalf of others users on a Exchange mailbox. This decision was later changed to use the individual users own credentials. The user is prompted for their password and this is stored encrypted for their use only in a profile document. The following code snippet shows how communication with the Exchange server is set up in Java using the EWS API:

service = new ExchangeService(ExchangeVersion.Exchange2010_SP1);
// service.setTraceEnabled(true); // enable to trace the web service communication in the Java debug console
service.setUrl(new java.net.URI(server));
ExchangeCredentials credentials = new WebCredentials(userid, password);
service.setCredentials(credentials);

A meeting is simply created using the Appointment class. Time zone support is achieved by using UTC as the time zone for date details. To format dates as UTC I used the LSGMTTime  property of the NotesDateTime class.

Appointment appointment = new Appointment(service);
appointment.setSubject(subject);
appointment.setBody(MessageBody.getMessageBodyFromText(body));
appointment.setStart(formatter.parse(startDate));
appointment.setEnd(formatter.parse(endDate));
appointment.setLocation(location);
// Save as appointment - and not as a meeting with participants
appointment.save(SendInvitationsMode.SendToNone);

Importing mails is done by presenting the user with a list of mails from the users Exchange mailbox. The list is retrieved by looping through the Inbox folder:

ItemView view = new ItemView(100);
view.getOrderBy().add(ItemSchema.DateTimeReceived, SortDirection.Ascending);
FindItemsResults<Item> findResults;
findResults = service.findItems(WellKnownFolderName.Inbox, view);
service.loadPropertiesForItems(findResults.getItems(), new PropertySet(BasePropertySet.IdOnly, EmailMessageSchema.Subject, EmailMessageSchema.DateTimeReceived, EmailMessageSchema.Sender));

The user then selects a mail from the list and the corresponding mail in Exchange is retrieved with the unique item id as identifier.

EmailMessage message = EmailMessage.bind(service, new ItemId(mailItemId));

Rich text support between Notes and Outlook is handled using Lotusscript stream and mime classes:

Set stream = session.CreateStream
Call stream.WriteText(mailBody)
Set mime = doc.CreateMIMEEntity("Body")
Call mime.SetContentFromText (stream, "text/html;charset=UTF-8",ENC_NONE)

When sending mails from the Notes CRM application the user can access their Outlook contacts. The list of Outlook contacts is retrieved by looping through the Contacts folder:

ItemView view = new ItemView(2000);
view.getOrderBy().add(ContactSchema.DisplayName, SortDirection.Ascending);
FindItemsResults<Item> findResults;
findResults = service.findItems(WellKnownFolderName.Contacts, view);

The Microsoft Outlook client is launched when a meeting invitation is created in order for the user to finish the meeting invitation in Outlook. This is achieved by using the Shell Lotusscript command together with the fact that Outlook can be launched with a parameter that indicates what item to open when launched:

Shell( getOutlookPath() + " /select outlook:" + Ucase(doc.OutlookUniqueId(0)) )

The use of LS2J led to some performance issues at the customer site in the form of 10-20 seconds load times before a document was opened. The reason for this is that the Java code is extracted to disk whereby the Antivirus program at use at the customer site started to check all files for virus before the document could be opened. The customer modified the Antivirus settings to remove this check whereby the documents opened within reasonable time again.

DanNotes: The 46th Danish LUG conference is in November

DanNotes is the Danish Lotus user group. It started as a Lotus user group back in 1993 and has since then organized 2 day conferences for the Danish Lotus community with a schedule of 2 a year. The next conference in November is conference number 46! That’s an impressive number of conferences.

I am proud to have been selected as member of the board at the spring conference in May and I am thereby part of the group of organizers that plan the next conference.

I am really looking forward to meet Anders Holm Petersen who is the new country manager for IBM Collaboration Solutions in Denmark, to meet our great lineup of speakers: Niklas Heidloff, Stuart McIntyre, Ulrich Krause, and Chris Connor – and also to meet the many members of the Danish Lotus community.

If you are interested in joining the conference, then head over to the DanNotes website and register. There is a LinkedIn event and a Lanyrd event for the conference if you are interested in tracking the conference using social tools.

PHL Consult supports OpenNTF and open source

My company, PHL Consult, became member of OpenNTF in August and thereby supports OpenNTF and the use of open source within the Lotus Domino/XPages community. This means that I support the idea of open source in general (and support OpenNTF as an organization) – and that I both contribute code to and reuse code from OpenNTF. I have so far contributed 2 open source XPages custom controls to OpenNTF:

At the time of writing this blog post OpenNTF has 23 company members. Members according to OpenNTF are “companies with the common interest to provide open source for IBM Lotus Notes and Domino and to encourage broad industry use of these applications. To achieve these goals members are willing to devote resources or participate in other ways”.