예제 #1
0
  public String[] sendEmailsToAddresses(
      String from,
      String[] to,
      String subject,
      String message,
      boolean deferExceptions,
      String deliveryOption) {
    if (deliveryOption == null || "".equals(deliveryOption)) {
      deliveryOption = EvalConstants.EMAIL_DELIVERY_DEFAULT;
    }
    if (to == null) {
      throw new IllegalArgumentException("to cannot be null");
    }

    String[] emails = to;
    if (EvalConstants.EMAIL_DELIVERY_SEND.equals(deliveryOption)) {
      emails = externalLogic.sendEmailsToAddresses(from, to, subject, message, deferExceptions);
    } else if (EvalConstants.EMAIL_DELIVERY_LOG.equals(deliveryOption)) {
      for (String email : emails) {
        LOG.debug(
            "Delivery LOG: from ("
                + from
                + ") to ("
                + email
                + ") subject ("
                + subject
                + "):\n"
                + message);
      }
    } else {
      LOG.warn(
          "Delivery NONE: No emails sent or logged: from ("
              + from
              + ") to ("
              + ArrayUtils.arrayToString(to)
              + ") subject ("
              + subject
              + ")");
    }
    return emails;
  }
예제 #2
0
  public String[] sendEmailsToUsers(
      String from,
      String[] toUserIds,
      String subject,
      String message,
      boolean deferExceptions,
      String deliveryOption) {
    // handle the list of TO addresses
    List<EvalUser> l = getEvalUsersByIds(toUserIds);
    List<String> toEmails = new ArrayList<>();
    // email address validity is checked at entry but value should not be null
    for (Iterator<EvalUser> iterator = l.iterator(); iterator.hasNext(); ) {
      EvalUser user = iterator.next();
      if (user.email == null || "".equals(user.email)) {
        iterator.remove();
        LOG.warn(
            "sendEmails: Could not get an email address for "
                + user.displayName
                + " ("
                + user.userId
                + ")");
      } else {
        toEmails.add(user.email);
      }
    }

    if (!l.isEmpty()) {
      LOG.warn(
          "No users with email addresses found in the provided userIds ("
              + ArrayUtils.arrayToString(toUserIds)
              + "), cannot send email so exiting");
      return new String[] {};
    }

    return sendEmailsToAddresses(
        from, toEmails.toArray(new String[] {}), subject, message, deferExceptions, deliveryOption);
  }