简体   繁体   中英

mailto in Java?

I am trying to set a hyperlink in my eclipse java project. when someone clicks on a button, it should open up an email client along with the given email id. is it possible to implement it with java.awt.Desktop?

Yes it is possible using desktop.mail()

Desktop desktop = Desktop.getDesktop();
String message = "mailto:dummy@domain.com?subject=First%20Email";
URI uri = URI.create(message);
desktop.mail(uri);

and regarding the mailto URI you have to create it yourself.

A mailto: URI can specify message fields including "to", "cc", "subject", "body", etc. See The mailto URL scheme (RFC 2368) for the mailto: URI specification details.

What's wrong with java.awt.Desktop.mail(URI mailtoURI) ??

edit

as for usage:

   Desktop desktop = getDesktop(); 
   desktop.mail(new URI("mailto:name@hotmail.com"));

You need to construct an URI instance and pass it to Destkop.mail .

Here's a helpful wiki article about constructing mailto URIs.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM