Other Examples

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

Your Java code should always start with the call to com.linar.jintegra.AuthInfo.setDefault(string domain, string username, string password). This is a way of having your Java program authenticate itself to Windows so it can access CDO/Exchange Server. The parameters to this call are the credentials of the service account used to configure CDO. It is only after a successful authentication that your Java program is allowed access to the Exchange Server.

Once authenticated, you begin accessing Exchange Server objects through the Session object. The Session object has a logon method where you indicate the name of the Exchange Server you wish to connect to and and the mailbox you wish to access.

import com.intrinsyc.cdo.*;

public class SampleProgram {

    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 {
            // use credentials of service account to 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);

            // print the current user for this Session
            AddressEntry user = new AddressEntryProxy(session.getCurrentUser());
            System.out.println("Current user: " + user.getName());

            

            // do work here . . . .

            

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

        } catch (Exception ex) {
            ex.printStackTrace();
        }finally{
            // clean up and release all references
            com.linar.jintegra.Cleaner.releaseAll();
        }
    }
}