Thursday, February 14, 2013

Using Exchange process mailboxes with Java

In a world where servers are under constant attack, the wise will use the few facilities that can be easily hardened in a firewall and with defensive programming, like servlets. Sometimes it is useful to have something more simple than a web service, such as an email service. For example, you could take a picture with your mobile device and mail it to mostlycolor for a consultation by an automated color advisor.

It is easy to find the information to quickly code up an email client using the JavaMail API and the JavaBeans Activation Framework. Suppose your email is martin.muster@mostlycolor.ch with password !@#$% and your host is mailhub.mostlycolor.ch. You the access your mailbox with the simple statement

store.connect ("mailhub.mostlycolor.ch", "martin.muster@mostlycolor.ch", "!@#$%");

In practice, you do not want to use your mailbox for an automated service, but you want to use a so-called process mailbox on your Exchange server, say color.advisor@mostlycolor.ch. This seems obvious, but I was not able to formulate the correct query to find out how to access a process mailbox. Here is what I found out by trial and error.

Suppose your domain is americas and your login name is musterm. The connect statement then becomes

store.connect ("mailhub.mostlycolor.ch", "americas\\musterm\\color.advisor@mostlycolor.ch", "!@#$%");

Pretty simple once you know the syntax!