Here is an example using the java.awt.Desktop
class to open user’s default mail client application. There are two methods provided, the mail()
and the mail(URI uri)
methods.
When specifying the URI
to the application will be opened with the message field filled with the mailto
information. You can refer to the following document for the valid mailto
URI scheme http://www.ietf.org/rfc/rfc2368.txt
package org.kodejava.awt;
import java.awt.*;
import java.io.IOException;
import java.net.URI;
public class RunningDefaultMailClient {
public static void main(String[] args) {
// Get an instance of Desktop. An UnsupportedOperationException will
// be thrown if the platform doesn't support Desktop API.
Desktop desktop = Desktop.getDesktop();
try {
// Open user-default mail client application.
desktop.mail();
} catch (IOException e) {
e.printStackTrace();
}
try {
// Open user-default mail client with the email message fields information.
String message = "mailto:dummy@example.com?cc=test@example.com&subject=First%20Email";
URI uri = URI.create(message);
desktop.mail(uri);
} catch (IOException e) {
e.printStackTrace();
}
}
}
Latest posts by Wayan (see all)
- How do I split large excel file into multiple smaller files? - April 15, 2023
- How do I get the number of processors available to the JVM? - March 29, 2023
- How do I show Spring transaction in log / console? - March 29, 2023