本文介绍了Java:打开默认邮件应用程序并创建新邮件并填充To和Subject字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否有Java中的功能来生成一段可以打开的代码用户PC上的默认电子邮件应用程序? (我想几乎喜欢一个花哨的邮件链接...)
如果有 - 是否可以填充To和Subject字段等字段?
谢谢,
Mike。
解决方案
Desktop.mail(URI mailtoURI )是您的朋友!
Javadoc:
示例代码:
桌面桌面;
if(Desktop.isDesktopSupported()
&&(desktop = Desktop.getDesktop())。isSupported(Desktop.Action.MAIL)){
URI mailto = new URI(邮寄地址:[email protected]主题=你好%20World);
desktop.mail(mailto);
} else {
// TODO fallback to some Runtime.exec(..)voodoo?
抛出新的RuntimeException(桌面不支持mailto;邮件已经死了));
}
Just wondering if anyone can help me with a problem I've come across in Java.
Is there functionality within Java to produce a section of code that will open the default email application on a user's PC? (I guess almost like a fancy mailto link...)
If there is - is it possible to populate fields such as the To and Subject fields?
Thanks,Mike.
解决方案
Desktop.mail(URI mailtoURI) is your friend!
Javadoc:
Example Code:
Desktop desktop;
if (Desktop.isDesktopSupported()
&& (desktop = Desktop.getDesktop()).isSupported(Desktop.Action.MAIL)) {
URI mailto = new URI("mailto:[email protected]?subject=Hello%20World");
desktop.mail(mailto);
} else {
// TODO fallback to some Runtime.exec(..) voodoo?
throw new RuntimeException("desktop doesn't support mailto; mail is dead anyway ;)");
}
这篇关于Java:打开默认邮件应用程序并创建新邮件并填充To和Subject字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!