【问题标题】:Implementing a 'Send Feedback' feature in a Java desktop application在 Java 桌面应用程序中实现“发送反馈”功能
【发布时间】:2010-02-18 16:14:46
【问题描述】:

我想在 Java 桌面应用程序中实现“发送反馈”选项。一个会弹出一个框供用户输入评论,然后将其与应用程序窗口的屏幕截图一起发送给我们。

向我们传达数据的最佳方式是什么?我想到了两个明显的解决方案:

  • 电子邮件 - 我认为应用程序将连接到我们设置的 SMTP 服务器,用户名/密码以某种方式隐藏在代码中。 SMTP over SSL 以确保安全(不是发送的数据,而是 SMTP 用户名/密码)。
  • Web 服务 - 不言自明。

其中哪一个是最好的,或者有更好的选择吗?

【问题讨论】:

    标签: java web-services email desktop feedback


    【解决方案1】:

    网络服务会好得多,因为与 SMTP 服务器的连接可能会被阻止。

    另一个想法是使用 Google Docs。这就像网站的想法,但您不需要自己设置任何服务器端的东西。您可以使用要收集的字段创建一个 Google Docs 电子表格,然后让您的 Java 应用程序使用 google docs API 将提交内容写入 spreadhseet。然后在电子表格中添加通知,以便在写入新行时自动向您发送电子邮件。

    【讨论】:

    • Google 文档是一个很棒的主意。我可能会为自己的项目走这条路。
    • 谢谢...我真的很喜欢 Google Docs 的想法。我们现在要制作原型 :)
    • 这确实是个好主意。
    • 我们已经对 Google Docs 解决方案进行了原型设计,并且运行良好,因此我们将继续使用它 :)
    【解决方案2】:

    Web 服务听起来更可靠且不那么笨拙。 客户端通常可以在没有防火墙问题的情况下建立 HTTP 连接。 更容易设置、维护和处理 HTTP 服务器和请求。

    【讨论】:

      【解决方案3】:

      正如其他人所提到的,防火墙是 SMTP 的一个问题。不过,有一种简单的方法可以在不托管您自己的基础设施或“隐藏”密码的情况下传递邮件。您可以简单地注册一个免费邮件帐户,例如gmail,并将邮件直接发送到此地址。由于您没有使用 Gmail 的 SMTP 服务器作为中继,因此不需要用户名和密码。

      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;
      }
      

      例如:

      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")));
      }
      

      所以您将使用“gmail-smtp-in.l.google.com”作为 javax.mail 的首选:

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

      您甚至可以将此方法与托管在 AppEngine 上的简单 HTTP 到 SMTP 服务相结合。它所要做的就是接收 HTTP POST 请求并使用上面显示的方法将它们作为电子邮件转发。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2012-10-09
        • 2022-12-12
        • 1970-01-01
        • 1970-01-01
        • 2014-02-23
        • 2010-11-26
        • 1970-01-01
        相关资源
        最近更新 更多