如何使用指定客户端以 Java 编程方式发送电子邮件附件
我想鼓励 RCP 应用程序的用户将问题详细信息发送给我们的支持部门。 为此,我在我们的标准错误对话框中添加了一个“联系支持”小部件。
我已经成功地使用 URI 标头通过 Java 6 的 JDIC 调用发送堆栈跟踪: Desktop.getDesktop().mail(java.net.URI)
。 这将启动用户的邮件客户端,准备好添加评论,然后点击发送。
我喜欢启动电子邮件客户端,因为这是用户所习惯的,它告诉支持人员很多有关用户的信息(签名、联系方式等),而我真的不想要 与 Java Mail 一起发布。
我想做的是将日志文件和堆栈跟踪作为文件附加,因此没有最大长度要求,用户会看到一封漂亮干净的电子邮件,并且支持部门有更多信息可供使用。
我可以用我正在采取的方法来做到这一点吗? 或者,还有更好的方法?
编辑: 我处于 OSGi 环境中,因此捆绑 JDIC 是必要的。 如果可能的话,我希望提供尽可能少的依赖项,并且为多个平台捆绑 JDIC 听起来并不有趣,尤其是对于这么小的功能。
JavaMail 可能适合,但事实上它将出现在我们企业客户的桌面上。 配置的设置/发现必须是透明的、自动的和可靠的。 关于JavaMail,配置似乎只能手动进行。 是这样吗?
我最喜欢的答案是对 *.eml 文件使用 Desktop.open()
。 不幸的是Outlook Express(而不是Outlook)打开eml 文件。 我不知道 Windows 配置为打开这样的 EML 文件是常见的还是默认的。 这是常见的吗? 或者是否有另一种基于文本的格式,a)很容易生成,b)默认在用户已经使用的同一电子邮件客户端中打开?
I'd like to encourage our users of our RCP application to send the problem details to our support department. To this end, I've added a "Contact support" widget to our standard error dialogue.
I've managed to use URI headers to send a stacktrace using Java 6's JDIC call: Desktop.getDesktop().mail(java.net.URI)
. This will fire up the user's mail client, ready for them to add their comments, and hit send.
I like firing up the email client, because it's what the user is used to, it tells support a whole lot about the user (sigs, contact details etc) and I don't really want to ship with Java Mail.
What I'd like to do is attach the log file and the stacktrace as a file, so there is no maximum length requirement, and the user sees a nice clean looking email, and the support department has a lot more information to work with.
Can I do this with the approach I'm taking? Or is there a better way?
Edit:
I'm in an OSGi context, so bundling JDIC would be necessary. If possible, I'd like to ship with as few dependencies as possible, and bundling up the JDIC for multiple platforms does not sound fun, especially for such a small feature.
JavaMail may be suitable, but for the fact that this will be on desktops of our corporate clients. The setup/discovery of configuration would have to be transparent, automatic and reliable. Regarding JavaMail, configuration seems to be manual only. Is this the case?
The answer I like most is using the Desktop.open()
for an *.eml file. Unfortunately Outlook Express (rather than Outlook) opens eml files. I have no idea if this is usual or default to have Windows configured for to open EML files like this. Is this usual? Or is there another text based format that a) is easy to generate, b) opens by default in the same email client as users would be using already?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
您可以保存临时 .eml 文件,然后 Desktop.getDesktop().open(emlFile)
编辑:正如您所指出的,不幸的是,这将打开 Outlook Express 而不是 Outlook。
但是,如果您安装了 Windows Live Mail,它将使用它。
You could save a temporary .eml file, and Desktop.getDesktop().open(emlFile)
Edit: As you point out, this will unfortunately open outlook express instead of outlook.
However if you have Windows Live Mail installed, it will use that.
如果您使用 JDK 6(您确实应该使用),那么桌面 API 现在是 JRE 的一部分。 请参阅 http://java.sun.com/developer/technicalArticles/ J2SE/Desktop/javase6/desktop_api/ 了解更多信息。
If you're using JDK 6 (you really should), the Desktop API is now part of the JRE. See http://java.sun.com/developer/technicalArticles/J2SE/Desktop/javase6/desktop_api/ for more information.
作为处理同一问题的完全不同的方式,我们使用带有 XML-RPC 接口的错误跟踪器,并且我们的(顺便说一句,RCP)应用程序使用自定义提交对话与之对话。 这意味着我们可以发送日志文件来帮助诊断问题,而无需用户查找它们。
我确信大多数错误跟踪器都有类似的功能。 我们使用 Jira,而且效果很好(显然,他们刚刚发布了免费的个人版本,可以轻松尝试)。
As a completely different way of handling the same problem, we use a bug tracker with an XML-RPC interface, and our (RCP also, btw) app talks to that using a custom submission dialogue. It means we can send the log files to help diagnose the problem, without the user having to find them.
I'm sure most bug trackers have something like this available. We use Jira, and it works great (apparently, they've just released a free Personal version that makes it easy to try).
使用该方法,您可以使用 URI 设置主题行和正文文本,例如
但是,主题和正文文本的长度将为 有一些限制
我无法想到使用此方法或类似的方法附加文件(无需将 javamail 添加到您的应用程序)
Using that method, you can set the subject line and body text with a URI like
However, the length of the subject and body text will have some limitation
There is no way I can think of to attatch a file using this method or something similar (without adding javamail to your app)
JDIC 可能并不总是在您的用户平台上可用。 执行此操作的一个好方法是使用 javamail API。 您可以发送多部分电子邮件消息,如 SUN 在本教程中所述:
发送附件
JDIC may not always be available on your user's platform. A good way to do this is to use the javamail API. You can send a multi-part e-mail message as explained in this tutorial by SUN:
Sending Attachments