private static String getBody(
      Map<AcquisitionProcessStateType, MultiCounter<AcquisitionProcessStateType>> acquisitionMap,
      Map<RefundProcessStateType, MultiCounter<RefundProcessStateType>> refundMap,
      final VirtualHost virtualHost) {

    final StringBuilder builder =
        new StringBuilder("Caro utilizador, possui processos de aquisições pendentes nas ");
    builder.append(virtualHost.getApplicationSubTitle().getContent());
    builder.append(", em https://");
    builder.append(virtualHost.getHostname());
    builder.append("/.\n");

    if (!acquisitionMap.isEmpty()) {
      builder.append("Regime simplificado\n");
      for (final MultiCounter<AcquisitionProcessStateType> multiCounter : acquisitionMap.values()) {
        builder.append("\t");
        builder.append(multiCounter.getCountableObject().getLocalizedName());
        builder.append("\t");
        builder.append(ProcessMapGenerator.getDefaultCounter(multiCounter).getValue());
        builder.append("\n");
        final Set<SimplifiedProcedureProcess> processes =
            (Set) ProcessMapGenerator.getDefaultCounter(multiCounter).getObjects();
        if (processes.size() < 25) {
          for (final SimplifiedProcedureProcess process : processes) {
            builder.append("\t\t");
            builder.append(process.getProcessNumber());
            builder.append("\n");
          }
        }
      }
    }
    if (!refundMap.isEmpty()) {
      builder.append("Processos de reembolso\n");
      for (final MultiCounter<RefundProcessStateType> multiCounter : refundMap.values()) {
        builder.append("\t");
        builder.append(multiCounter.getCountableObject().getLocalizedName());
        builder.append("\t");
        builder.append(ProcessMapGenerator.getDefaultCounter(multiCounter).getValue());
        builder.append("\n");
        final Set<RefundProcess> processes =
            (Set) ProcessMapGenerator.getDefaultCounter(multiCounter).getObjects();
        if (processes.size() < 25) {
          for (final RefundProcess process : processes) {
            builder.append("\t\t");
            builder.append(process.getProcessNumber());
            builder.append("\n");
          }
        }
      }
    }
    return builder.toString();
  }
  public static void executeTask() {
    final String ts = new DateTime().toString("yyyy-MM-dd HH:mm:ss");
    final VirtualHost virtualHost = VirtualHost.getVirtualHostForThread();

    List<String> toAddress = new ArrayList<String>();
    Language.setLocale(Language.getDefaultLocale());
    for (Person person : getPeopleToProcess()) {
      Authenticate.authenticate(person.getUsername(), StringUtils.EMPTY, false);
      Map<AcquisitionProcessStateType, MultiCounter<AcquisitionProcessStateType>>
          generateAcquisitionMap = ProcessMapGenerator.generateAcquisitionMap(person, true);
      Map<RefundProcessStateType, MultiCounter<RefundProcessStateType>> generateRefundMap =
          ProcessMapGenerator.generateRefundMap(person, true);

      if (!generateAcquisitionMap.isEmpty() || !generateRefundMap.isEmpty()) {
        toAddress.clear();
        try {
          final String email = person.getEmail();
          if (email != null) {
            final Sender sender = virtualHost.getSystemSender();
            final PersistentGroup group = SingleUserGroup.getOrCreateGroup(person.getUser());
            new Message(
                sender,
                Collections.EMPTY_SET,
                Collections.singleton(group),
                Collections.EMPTY_SET,
                Collections.EMPTY_SET,
                null,
                "Processos Pendentes - Aquisições",
                getBody(generateAcquisitionMap, generateRefundMap, virtualHost),
                null);
          }
        } catch (final Throwable ex) {
          System.out.println("Unable to lookup email address for: " + person.getUsername());
          // skip this person... keep going to next.
        }
      }
    }
  }
 public static boolean isActive() {
   final VirtualHost virtualHost = VirtualHost.getVirtualHostForThread();
   return virtualHost != null && isActive(virtualHost.getHostname());
 }