Integrating a Lotus Notes application with Exchange
September 29th, 2011I 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.
Tags: Java, Lotus Domino, Lotus Notes, Lotusscript, Microsoft Exchange, Microsoft Outlook
September 29th, 2011 at 16:28
Thanks for the information. We are running into this situation more and more.
September 29th, 2011 at 17:13
Dude... you rock. That's hard-core sh*t. Nice job!
January 5th, 2012 at 02:36
Hi! This article ended up in my web search when I was looking for a Lotus Notes client that will integrate Outlook email/Calendar and Contacts or an Outlook client that will also pull Lotus Notes email, calendar and contacts. Would love to discuss in more detail if you would have time to chat over the phone. Thank you!
January 5th, 2012 at 12:20
Hi Ibo, I will contact you via email to proceed further. Thanks