Esempio n. 1
0
  /**
   * Opens the default mail application with the given email address as {@link String}.
   *
   * @param emailAddress for the mail (e.g. "*****@*****.**").
   * @throws IOException
   * @throws URISyntaxException
   * @see URI
   * @since 0.9.5
   */
  public static void mail(final String emailAddress)
      throws IOException, URISyntaxException { // $JUnit$
    if (log.isDebugEnabled()) log.debug(HelperLog.methodStart(emailAddress));
    if (null == emailAddress) {
      throw new RuntimeExceptionIsNull("emailAddress"); // $NON-NLS-1$
    }
    if (!HelperString.isValid(emailAddress)) {
      throw new RuntimeExceptionIsEmpty("emailAddress"); // $NON-NLS-1$
    }

    final String prefix = "mailto:"; // $NON-NLS-1$

    if (HelperString.startsWith(emailAddress, prefix)) {
      mail(new URI(emailAddress));
    } else {
      // best guess - add the prefix
      mail(new URI(prefix + emailAddress));
    }

    if (log.isDebugEnabled()) log.debug(HelperLog.methodExit());
  }
Esempio n. 2
0
  /**
   * Opens the default mail application with a given subject, body and addresses.
   *
   * @param subject for the mail
   * @param body for the mail
   * @param emailAddresses for the mail (e.g. "*****@*****.**")
   * @throws IOException
   * @throws URISyntaxException
   * @since 0.7.0
   */
  public static void mail(final String subject, final String body, final String... emailAddresses)
      throws IOException, URISyntaxException { // $JUnit$
    if (log.isDebugEnabled()) log.debug(HelperLog.methodStart(subject, body, emailAddresses));
    if (null == subject) {
      throw new RuntimeExceptionIsNull("subject"); // $NON-NLS-1$
    }
    if (!HelperString.isValid(subject)) {
      throw new RuntimeExceptionIsEmpty("subject"); // $NON-NLS-1$
    }
    //		if (null == body) {
    //			throw new RuntimeExceptionIsNull("body"); //$NON-NLS-1$
    //		}
    if (null == emailAddresses) {
      throw new RuntimeExceptionIsNull("emailAddresses"); // $NON-NLS-1$
    }
    if (!HelperArray.isValid(emailAddresses)) {
      throw new RuntimeExceptionIsEmpty("emailAddresses"); // $NON-NLS-1$
    }

    final StringBuilder sb = new StringBuilder();
    sb.append("mailto:"); // $NON-NLS-1$
    for (final String address : emailAddresses) {
      if (null == address) {
        throw new RuntimeExceptionIsNull("address"); // $NON-NLS-1$
      }
      if (0 < sb.length()) {
        sb.append(HelperString.COMMA);
      }

      sb.append(
          URLEncoder.encode(address, Constants.ENCODING_UTF8)
              .replace(HelperString.PLUS_SIGN, HEX_SPACE));
    }
    sb.append("?subject="); // $NON-NLS-1$
    sb.append(
        URLEncoder.encode(subject, Constants.ENCODING_UTF8)
            .replace(HelperString.PLUS_SIGN, HEX_SPACE));

    if (null != body) {
      sb.append("&body="); // $NON-NLS-1$
      sb.append(
          URLEncoder.encode(body, Constants.ENCODING_UTF8)
              .replace(HelperString.PLUS_SIGN, HEX_SPACE));
    }

    mail(new URI(sb.toString()));

    if (log.isDebugEnabled()) log.debug(HelperLog.methodExit());
  }