Saturday, 8 June 2013

Talend: Integrate MS exchange server with Talend - create tasks 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 task 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;
import microsoft.exchange.webservices.data.Task;
import microsoft.exchange.webservices.data.TasksFolder;
import microsoft.exchange.webservices.data.TaskStatus;
import microsoft.exchange.webservices.data.BodyType;



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

Task newtask;
newtask = new Task(service);
MessageBody msgBody;
msgBody = new MessageBody();
msgBody.setText("Agenda comes here - we can add text here");
msgBody.setBodyType(BodyType.Text);
newtask.setBody(msgBody);
newtask.setDueDate(TalendDate.addDate(TalendDate.getCurrentDate(), 1, "dd"));
newtask.setSubject("task subject comes here");
...
...
newtask.save();

No comments:

Post a Comment