Working with Fields/Properties

Make sure you have completed all the configuration requirements before running any of the examples.

Every object in the Exchange Server, be it a message or a collection of messages, folder, collection of folders, appointments, etc has a list of fields or properties that you can access and manipulate to change the underlying object. In fact, if you have done MAPI programming, you are well aware that is through these fields/properties that you are able to have greater control over objects in the Exchange Server. For instance, the Message class in the CDO API provides getter/setter methods for only the most commonly-accessed properties like subject, body, sender, recipients, etc. If you wish to access more arcane properties including user-defined fields, the only way to do this is through the Fields object. The following examples demonstrate how to work with fields/properties.

  1. Listing all the Fields of a Message

  2. How to Set the Value of a Field

1. Listing all the Fields of a Message

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

public class FieldsExample {

    public static void main(String[] args) {

        //TODO: Change the following parameters based on your setup and configuration
        // the logon parameters of the service account you used to configure CDO
        String domain           = "mydomain";
        String username         = "jsmith";
        String password         = "password";

        // the DNS name or IP address of the machine where you installed CDO
        String CDOmachine       = "0.0.0.0";

        // the DNS name or IP address of the Exchange Server
        String exchangeServer   = "0.0.0.0";

        // the mailbox you wish to access (NOTE: this is the same as the user's login name
        // e.g., if the username is jsmith, mailbox would also be jsmith )
        String mailbox          = "jsmith";

        try {
            // authenticate to Windows
            com.linar.jintegra.AuthInfo.setDefault(domain, username, password);

            // create a Session in the CDOmachine
            Session session = new Session(CDOmachine);

            // logon to the Exchange Server
            session.logon(null, null, new Boolean(false), new Boolean(true),
                          new Boolean(false), new Boolean(false),
                          exchangeServer + "\n" + mailbox);

            // retrieve the inbox folder
            Integer folderType = new Integer(CdoDefaultFolderTypes.CdoDefaultFolderInbox);
            Folder inbox = new FolderProxy(session.getDefaultFolder(folderType));

            // get the message collection from the inbox
            Messages messages = new MessagesProxy(inbox.getMessages());

            // get the first message in the collection
            Message message = new MessageProxy(messages.getItem(new Integer(1)));

            // get the fields collection of the message
            Fields fields = new FieldsProxy(message.getFields());

            // print out all the fields and their corresponding values
            int count = ((Integer)fields.getCount()).intValue();
            for(int i=1; i<=count; i++){
                Field field = new FieldProxy(fields.getItem(new Integer(i), null));
                System.out.println(i + ". --------------------------------------");
                System.out.println("Field name  : " + field.getName());
                System.out.println("Field ID    : " + field.getID());
                System.out.println("Data type   : " + field.getType());
                System.out.println("Field Value : " + field.getValue());
            }

            // logoff from the session
            session.logoff();

        } catch (Exception ex) {
            ex.printStackTrace();
        }finally{
            Cleaner.releaseAll();
        }
    }
}

2. How to Set the Value of a Field

Refer to the contacts example on how to set the value of fields/properties.