Saturday, 8 June 2013

Talend: Integrate MS exchange server with Talend - create contacts in exchange server using EWS



Problem - There is a need to integrate Microsoft exchange server with Talend. One such requirement is to create a new contact in exchange server using Talend.

Solution -  As of date i could not find any builtin talend component to do this integration of exchange server with talend. What we can do is to use java code and exchange web service and EWSJavaapi to help us here.

Required jar files for this integration - commons-httpclient-3.0.1.jar, commons-codec-1.2.jar, commons-logging-1.1.3.jar, EWSJavaAPI_1.2.jar, jcifs-1.3.17.jar.

EWSJavaAPI_1.2.jar - exposes some java classes and methods which allows us to integrate talend (using java code) and exchange server.






tLibrary is used to load above required jar files in the job.

import of classes in tJava component is below
import java.net.URI;
import java.net.URISyntaxException;
import microsoft.exchange.webservices.data.ExchangeCredentials;
import microsoft.exchange.webservices.data.ExchangeService;
import microsoft.exchange.webservices.data.EmailMessage;
import microsoft.exchange.webservices.data.InternetMessageHeader;
import microsoft.exchange.webservices.data.InternetMessageHeaderCollection;
import microsoft.exchange.webservices.data.MessageBody;
import microsoft.exchange.webservices.data.ExchangeVersion;
import microsoft.exchange.webservices.data.FindItemsResults;
import microsoft.exchange.webservices.data.WebCredentials;
import microsoft.exchange.webservices.data.WellKnownFolderName;
import microsoft.exchange.webservices.data.Contact;

code used in tJava component (in job above) is below

ExchangeService service = new ExchangeService(
    ExchangeVersion.Exchange2007_SP1);
    ExchangeCredentials credentials = new WebCredentials("UserName","UserPassword");
    service.setCredentials(credentials);
    try {
        service.setUrl(new URI("https://exchange.domain.com/ews/Exchange.asmx"));
    } catch (URISyntaxException e) {
        e.printStackTrace();
    }

System.out.println(new Date() + "-INFO - Creating new contact");       
Contact contact = new Contact(service);

contact.setDisplayName("Contact Display Name comes here");
contact.setBusinessHomePage("www.homepageofcontact.com");
...
...
contact.save(WellKnownFolderName.Contacts);

3 comments:

  1. Very informative, Thanks for sharing, But I came across some other code samples, here are the links:
    http://www.aspose.com/docs/display/emailnet/Send+Email+Messages+using+Exchange+Server
    http://www.aspose.com/docs/display/emailnet/Manage+Conversation+Items+on+Exchange+Server
    http://www.aspose.com/docs/display/emailnet/List+Messages+on+an+Exchange+Server

    It also available for java Language, here is the link: http://www.aspose.com/java/email-component.aspx

    ReplyDelete
  2. Very informative, Thanks for sharing, But I came across another java email component by the name of Aspose.Email for Java. It enables Java applications to read and write MS Outlook MSG files from within a Java application without using MS Outlook. I am sure it will be helpful. Here some code example with Exchange server

    http://www.aspose.com/docs/display/emailnet/Send+Email+Messages+using+Exchange+Server

    http://www.aspose.com/docs/display/emailnet/Manage+Conversation+Items+on+Exchange+Server

    ReplyDelete
  3. While Searching for my problem I cam accross this nice code samples. You can Send Email Messages using Exchange Server
    with the help of the tools in the Aspose.Email.Exchange. The ExchangeClient.Send() method accepts a MailMessage instance as a parameter and sends the email. Moreover, Aspose.Email provides the ExchangeWebServiceClient class to connect to Microsoft Exchange Server using Exchange Web Services. The code snippets that follow uses EWS to send emails using Microsoft Exchange Server.

    ReplyDelete