Java Swing Tutorial - Java Desktop.mail(URI mailtoURI)








Syntax

Desktop.mail(URI mailtoURI) has the following syntax.

public void mail(URI mailtoURI)  throws IOException

Example

In the following code shows how to use Desktop.mail(URI mailtoURI) method.

//w w  w. jav a 2 s .  co  m

import java.awt.Desktop;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;

public class Main {
  public static void main(String[] a) throws URISyntaxException {
    try {
      Desktop desktop = null;
      if (Desktop.isDesktopSupported()) {
        desktop = Desktop.getDesktop();
      }

       desktop.mail(new URI("name@address.net"));
    } catch (IOException ioe) {
      ioe.printStackTrace();
    }

  }
}