Use default client for mailing - JDK6
Sending mails or messaging from Java is never been a tough process but still most of us has to write Java Messaging API or Java Mail API to do this, which is a cumbersome process in itself.
JDK6 came with a new Desktop class in which you can give user the option to work on the default mail client, do whatever you want to do and after closing the default client the control will go back to the java code. Here is a small code to do that:
import java.awt.Desktop;
import java.io.IOException;
import java.net.URI;
public class DefaultMail {
public static void main(String[] a)throws Exception {
Desktop desktop = null;
if (Desktop.isDesktopSupported()) {
desktop = Desktop.getDesktop();
}
desktop.mail(”mailto”, “vaibhav.choudhary@sun.com”, null);
}
}
The idea is clean I guess, the default client will give more option than Java mail API or anything else. Desktop class give lot more other functionality as well, which we will discuss later.











Java,JavaScript,Threading,
Optimization and more with Vaibhav 



July 29th, 2008 at 11:18 pm
hi there,
I tried this on jdk 1.6.0_07 but the desktop.mail() method did not compile. which version of JDK are you using ?
thank you.
BR,
~A
August 1st, 2008 at 3:16 pm
Ya it should work on 1.6.0. What is the error you are getting ?
August 1st, 2008 at 3:17 pm
Maybe your system doesn’t have any default mail client