Search code examples
javaswtemail-client

How to check whether mail client application is installed on PC by java code?


Is there any way to check availability of mail client application on PC only through java code? Or Native method is the only way to check that?


Solution

  • Your best bet in the standard library is the Desktop class. It has 2 mail() methods which launch the mail composing window of the user default mail client.

    You can check if this is supported with the Desktop.isSupported(Desktop.Action.MAIL) call.

    Example:

    if (Desktop.isDesktopSupported()) {
        Desktop d = Desktop.getDesktop();
        if (d.isSupported(Desktop.Action.MAIL))
            d.mail(new URI("mailto:somebody@somehost.com?subject=test"));
    }