如何以跨平台的方式打开主题和正文的默认邮件程序? [英] How do I open the default mail program with a Subject and Body in a cross-platform way?
问题描述
如何以跨平台的方式打开主题和正文的默认邮件程序?
How do I open the default mail program with a Subject and Body in a cross-platform way?
不幸的是,这是一个用Java编写的客户端应用程序,不是一个网站。
Unfortunately, this is for a a client app written in Java, not a website.
我希望这可以跨平台的方式工作(这意味着Windows和Mac,对不起Linux)。我很高兴在Windows中执行VBScript,或者在OS X中执行AppleScript。但是我不知道这些脚本应该包含哪些内容。我想要执行用户的默认程序,而不是搜索Outlook或其他任何东西。
I would like this to work in a cross-platform way (which means Windows and Mac, sorry Linux). I am happy to execute a VBScript in Windows, or AppleScript in OS X. But I have no idea what those scripts should contain. I would love to execute the user's default program vs. just searching for Outlook or whatever.
在OS X中,我尝试执行命令:
In OS X, I have tried executing the command:
open mailto:?subject=MySubject&body=TheBody
需要使用URL转义来替换%20
的空格。
URL escaping is needed to replace spaces with %20
.
更新在Windows上,您必须玩各种游戏才能使开始
正确运行。这是正确的Java咒语:
Updated On Windows, you have to play all sorts of games to get start
to run correctly. Here is the proper Java incantation:
class Win32 extends OS {
public void email(String subject, String body) throws Exception {
String cmd = "cmd.exe /c start \"\" \"" + formatMailto(subject, body) + "\"";
Runtime.getRuntime().exec(cmd);
}
}
推荐答案
Java 1.6你有一个打破默认邮件平台的方法:
Desktop.mail(URI)方法。URI可用于设置邮件的所有字段(发件人,收件人,正文和主题)。
您可以在在Java SE 6中使用Desktop API
In Java 1.6 you have a stardard way to open the default mailer of the platform: the Desktop.mail(URI) method.The URI can be used to set all the fields of the mail (sender, recipients, body, subject). You can check a full example of desktop integration in Java 1.6 on Using the Desktop API in Java SE 6
这篇关于如何以跨平台的方式打开主题和正文的默认邮件程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!