views:

2264

answers:

6

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?

A: 

Using that method, you can set the subject line and body text with a URI like

mailto:[email protected]?SUBJECT=Support mail&BODY=This is a support mail

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)

tim_yates
+1  A: 

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.

Stephen Denne
This is ingenious. Unfortunately, on this dev box, Outlook is the default email client, and Outlook Express is the default app for eml files.
jamesh
A: 

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

entzik
+1  A: 

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.

Asgeir S. Nilsen
+1  A: 

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).

A: 
import java.awt.Desktop;
import java.io.File;
import java.net.URI;


public class TestMail {

    public static void main(String[] args) {
        try {       
         Runtime.getRuntime().exec(
                  new String[] {"rundll32", "url.dll,FileProtocolHandler",
                        "mailto:[email protected]?subject=someSubject&[email protected]&[email protected]&body=someBodyText&Attach=c:\\test\\test.doc"}, null
                  );


        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
Joeky