Home : J-Integra for Exchange : HOWTO : How to Send a Task Item
Q125224 - HOWTO: How to Send a Task Item

How to Send a Task Item

 

The following Java code shows how to create and send a task item using CDO and J-Integra for Exchange. For more information on CDO Type property fields, refer to
CDO Object Model.

import com.linar.jintegra.*;
import com.intrinsyc.cdo.*;
import java.util.Date;

public class SendTaskRequest {

    // Modify the following variables based on your specific setup
    // domain where the CDO host machine belongs, make sure it's all capitalized
    static String domain = "DOMAIN";
    // Java-Exchange username
    static String user = "username";
    // password of Java-Exchange user
    static String password = "password";
    // mailbox of Java-Exchange user
    static String mailbox    = "mailbox";
    // IP address or name of the CDO host machine
    static String CDOmachine = "000.000.000.000";
    // IP address or name of the Exchange Server
    static String exchangeServer = "000.000.000.000";
    // e-mail address of the person assigned for this task
    static String assignTo      = "someone@somewhere.com";

    // MAPI Constants to determine property set and individual properties
    // specific to task items
    static String CDOPROPSETID2 = "0320060000000000C000000000000046";
    static String CDOTASK_STARTDATE = "0x8104";
    static String CDOTASK_DUEDATE = "0x8105";
    static String CDOTASK_PERCENTCOMPLETE = "0x8102";

    public static void main(String[] args) {

        try {
            // Authenticate to NT domain via NTLM
            AuthInfo.setDefault(domain, user, password);

            // Start a MAPI Session
            Session session = new Session(CDOmachine);

            // Logon to the Exchange Server
            session.logon(null, null, null, null, null, null,
                          exchangeServer + "\n" + mailbox);

            // Retrieve task items for the Task Folder
            // Since CDO does not have direct support for Outlook task items,
            // we retrieve them as messages
            Integer folderID = new Integer(CdoDefaultFolderTypes.CdoDefaultFolderTasks);
            Folder taskFolder = new FolderProxy(session.getDefaultFolder(folderID));
            Messages tasks = new MessagesProxy(taskFolder.getMessages());

            // Add a task
            Message task = new MessageProxy(tasks.add(null, null, null, null));

            // Set task properties
            task.setSubject("Evaluate J-Integra for Exchange");
            task.setText("Perform a proof of concept for adding messaging capability " +
                         "to existing Web application by integrating Java and MS Exchange " +
                         "via interoperability tool called J-Integra for Exchange");
            task.setType("IPM.Task");

            // Set other task properties not readily accessible through CDO by
            // using some undocumented MAPI property tags
            Fields fields = new FieldsProxy(task.getFields());

            // Set the task start date
            Field  field = new FieldProxy(fields.add(
                    CDOTASK_STARTDATE,  // name of the property
                    new Integer(7),     // value data type, 7 maps to vbDate*
                    new Date(),         // value of the property
                    CDOPROPSETID2       // propSetID
            ));

            // Set the task end date
            Field  field2 = new FieldProxy(fields.add(
                    CDOTASK_DUEDATE,    // name of the property
                    new Integer(7),     // value data type, 7 maps to vbDate*
                    new Date(),         // value of the property
                    CDOPROPSETID2       // propSetID
            ));

            // Set the task's percent completion
            Field  field3 = new FieldProxy(fields.add(
                    CDOTASK_PERCENTCOMPLETE,    // name of the property
                    new Integer(5),     // value data type, 5 maps to vbDouble*
                    new Double(0.15),   // value of the property
                    CDOPROPSETID2       // propSetID
            ));

            // Create task recipient
            Recipients recipients = new RecipientsProxy(task.getRecipients());
            Recipient recipient = new RecipientProxy(recipients.add(null, null, null, null));
            recipient.setName(assignTo);

            // Each recipient added must be resolved before it can be used.
            // 0 == false to inhibit dialog boxes from popping up
            recipient.resolve(new Integer(0));

            // Update and send the task request
            task.update(new Boolean(true), new Boolean(true));
            task.send(new Boolean(true), null, null); // saves a copy in the sender's task folder

            System.out.println("Task request has been sent.");

            // Logoff and release all COM references
            session.logoff();
            Cleaner.releaseAll();

        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

}

Related Articles
No Related Articles Available.

Article Attachments
No Attachments Available.

Related External Links
No Related Links Available.
Help us improve this article...
What did you think of this article?

poor 
1
2
3
4
5
6
7
8
9
10

 excellent
Tell us why you rated the content this way. (optional)
 
Approved Comments...
No user comments available for this article.
Created on 6/23/2006.
Last Modified on 2/25/2009.
Last Modified by J-Integra KB Admin.
Article has been viewed 23157 times.
Rated 7 out of 10 based on 28 votes.
Print Article
Email Article