views:

119

answers:

3

I would like to implement a 'Send Feedback' option in a Java desktop application. One which will pop up a box for the user to enter a comment, then send it to us along with a screenshot of the application window.

How would be the best way to communicate the data to us? Two obvious solutions spring to mind:

  • Email - I'm thinking that the application would connect to an SMTP server set-up by us, with the username/password somehow hidden in the code. SMTP over SSL for security (not of the data being sent, but of the SMTP username/password).
  • Web service - pretty self explanatory.

Which of these would be best, or is there a better alternative?

+1  A: 

A web service sounds more reliable and less clumsy. Client generally may make HTTP connections without firewall issues. Much easier to setup, maintain and process HTTP server and requests.

Murali VP
+5  A: 

A webserivce would be far better, since the connection to an SMTP server might be blocked.

Another idea would be to use Google Docs. This would be like the website idea but you wouldnt need to set any server-side stuff yourself. You could create a Google Docs spreadsheet with the fields you will be collecting, then have your Java app write the submission to the spreadhseet using the google docs API. Then add a notification to the spreadsheet to automatically send you an email when a new row is written.

BigJoe714
Google Docs is an awesome idea. I might go that route for my own project.
unforgiven3
Thanks... I really like the Google Docs idea. We are going to prototype that now :)
William
It indeed is an awesome idea.
Murali VP
We have prototyped the Google Docs solution and it is working well, so we are going with that :)
William
+1  A: 

As others mention, firewalls are an issue with SMTP. Still, there is a simple way to deliver mails without hosting your own infrastructure or "hidden" passwords. You could simply register a free mail account, e.g. gmail, and send mails directly to this address. As you aren't using Gmail's SMTP server as a relay, there is no need for username and password.

public static String[] lookupMailHosts(final String domainName) throws NamingException {
    final InitialDirContext iDirC = new InitialDirContext();
    final Attributes attributes = iDirC
            .getAttributes("dns:/" + domainName, new String[] { "MX" });
    final Attribute attributeMX = attributes.get("MX");
    if (attributeMX == null) {
        return new String[] { domainName };
    }
    final String[][] pvhn = new String[attributeMX.size()][2];
    for (int i = 0; i < attributeMX.size(); i++) {
        pvhn[i] = ("" + attributeMX.get(i)).split("\\s+");
    }

    // sort the MX RRs by RR value (lower is preferred)
    Arrays.sort(pvhn, new Comparator<String[]>() {
        public int compare(final String[] o1, final String[] o2) {
            return Integer.parseInt(o1[0]) - Integer.parseInt(o2[0]);
        }
    });

    // put sorted host names in an array, get rid of any trailing '.'
    final String[] sortedHostNames = new String[pvhn.length];
    for (int i = 0; i < pvhn.length; i++) {
        sortedHostNames[i] = pvhn[i][1].endsWith(".") ? pvhn[i][1].substring(0, pvhn[i][1]
                .length() - 1) : pvhn[i][1];
    }
    return sortedHostNames;
}

for example:

public static void main(String[] args) throws Exception {
    // prints [gmail-smtp-in.l.google.com, alt1.gmail-smtp-in.l.google.com, alt2.gmail-smtp-in.l.google.com, alt3.gmail-smtp-in.l.google.com, alt4.gmail-smtp-in.l.google.com]
    System.out.println(Arrays.asList(lookupMailHosts("gmail.com")));
}

so you would use "gmail-smtp-in.l.google.com" as your first choice for javax.mail:

Properties props = new Properties();
props.setProperty("mail.smtp.host", lookupMailHosts("gmail.com")[0]);
// ... other properies
Session smtpSession = Session.getInstance(props, null)

You could even combine this approach with a simple HTTP to SMTP kind of service hosted on AppEngine. All it would have to do is receive HTTP POST requests and forward them as an email using the method shown above.

sfussenegger