简体   繁体   English

在Java中使用mailto?

[英]mailto in Java?

I am trying to set a hyperlink in my eclipse java project. 我想在我的eclipse java项目中设置一个超链接。 when someone clicks on a button, it should open up an email client along with the given email id. 当有人点击按钮时,它应该打开一个电子邮件客户端以及给定的电子邮件ID。 is it possible to implement it with java.awt.Desktop? 是否可以使用java.awt.Desktop实现它?

Yes it is possible using desktop.mail() 是的,可以使用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. 关于mailto URI,你必须自己创建它。

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. mailto:URI可以指定消息字段,包括“to”,“cc”,“subject”,“body”等。有关mailto:URI规范的详细信息,请参阅mailto URL方案(RFC 2368)

What's wrong with java.awt.Desktop.mail(URI mailtoURI) ?? 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 . 您需要构造一个URI实例并将其传递给Destkop.mail

Here's a helpful wiki article about constructing mailto URIs. 这是一篇关于构建mailto URI的有用维基文章

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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