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