Creating new mail (default client) from Java/Windows
Question
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:a@b.com?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).
OTHER TIPS
I found the answer when googling for rundll.exe:
String subject = ...;
String body = ...;
String cmd = "rundll32.exe shell32.dll,ShellExec_RunDLL \"mailto:a@b.com?"+
"subject="+subject+"&body="+body+"\"";
Runtime.getRuntime().exec(cmd);
Sorry for wasting your time!
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow