Search code examples
javawindowsexplorermailto

Creating new mail (default client) from Java/Windows


I want to open the "new mail" view using the default mail client (i.e. open a new mail form in Outlook). But when I go

String cmd = "explorer.exe \"mailto:[email protected]?subject="+
             subject+"&body="+body+"\"";
Runtime.getRuntime().exec(cmd);

the mail shows up, but I have a problem: explorer.exe brings up an Internet Explorer instance with a dummy page. Is there a better application to run, such as rundll.exe with certain arguments?

I know it is possible to do it without bringing up iexplore from C++, but I don't know how in Java.


Solution

  • Try with java.awt.Desktop (java 6)

    Desktop dt = Desktop.getDesktop();
    dt.mail();
    

    will open the default mail client (the one associated with mailto: protocol).