Home : Search Messages and Appointments by Entry ID
Q183230 - HOWTO: Search Messages and Appointments by Entry ID

How to Search and Retrieve Messages and Appointments by their Message ID

The following code demonstrates how to search an appointment item by its entry ID. You can apply the same example in searching for other Exchange item types like messages, contacts, task, etc. For more information on message ID's, please refer to the Microsoft CDO reference. Before you run this code, you should first configure CDO.

import com.intrinsyc.cdo.*;
import com.linar.jintegra.AuthInfo;

public class GetMessageByID {

    //TODO: Change the following parameters based on your setup and configuration
    static String domain            = "mydomain";
    static String user              = "jsmith";
    static String password          = "password";
    static String CDOmachine        = "0.0.0.0";
    static String exchangeServer    = "0.0.0.0";
    static String mailbox           = "jsmith";

    public static void main (String[] arg ){

        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, new Boolean(false), new Boolean(true),
                    new Integer(0), new Boolean(true),
                    exchangeServer + "\n" + mailbox);

            // Retrieve appointment items from the Calendar
            Integer folderID = new Integer(CdoDefaultFolderTypes.CdoDefaultFolderCalendar);
            Folder calendar = new FolderProxy(session.getDefaultFolder(folderID));
            Messages appointments = new MessagesProxy(calendar.getMessages());

            // Retrieve the first appointment item
            AppointmentItem cdoAppt = new AppointmentItemProxy(appointments.getFirst(null));

            // Retrieve the unique Entry ID of this appointment
            String ID = cdoAppt.getID().toString();
            System.out.println("Appointment ID : " + ID);

            // Get a reference to an appointment through its unique Entry ID
            AppointmentItemProxy apptUpdate = new AppointmentItemProxy(session.getMessage(ID, null));

            // Now update the location of the appointment
            System.out.println("Appointment location before update:" + apptUpdate.getLocation());
            apptUpdate.setLocation("Starbucks on Granville and Robson");
            System.out.println("Appointment location after update:" + apptUpdate.getLocation());
            apptUpdate.update(new Boolean(true), new Boolean(true));

            // How to check whether 2 id's are equal
            String ID2 = apptUpdate.getID().toString();
            System.out.println("Message ID : " + ID);
            System.out.println("Message ID2: " + ID2);
            System.out.println("Are IDs the same? " + session.compareIDs(ID, ID2));
            
            session.logoff();
        }
        catch(Exception e){
            e.printStackTrace();
        }
        finally{
            com.linar.jintegra.Cleaner.releaseAll();
        }
    }
}

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 10/18/2006.
Last Modified on 8/27/2008.
Last Modified by J-Integra KB Admin.
Article has been viewed 10973 times.
Rated 6 out of 10 based on 39 votes.
Print Article
Email Article