Showing posts with label create contact in ms exchange server using java. Show all posts
Showing posts with label create contact in ms exchange server using java. Show all posts

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);