/**
   * Send the email.
   *
   * @throws MojoExecutionException if the mail could not be sent
   */
  protected void sendMessage() throws MojoExecutionException {
    File templateFile = new File(templateOutputDirectory, template);
    String email = "";
    final MailSender ms = getActualMailSender();
    final String fromName = ms.getName();
    final String fromAddress = ms.getEmail();
    if (fromAddress == null || fromAddress.equals("")) {
      throw new MojoExecutionException(
          "Invalid mail sender: name and email is mandatory (" + ms + ").");
    }
    getLog()
        .info(
            "Using this sender for email announcement: " + fromAddress + " < " + fromName + " > ");
    try {
      MailMessage mailMsg = new MailMessage();
      mailMsg.setSubject(getSubject());
      mailMsg.setContent(IOUtil.toString(readAnnouncement(templateFile)));
      mailMsg.setContentType(this.mailContentType);
      mailMsg.setFrom(fromAddress, fromName);

      final Iterator it = getToAddresses().iterator();
      while (it.hasNext()) {
        email = it.next().toString();
        getLog().info("Sending mail to " + email + "...");
        mailMsg.addTo(email, "");
      }

      if (getCcAddresses() != null) {
        final Iterator it2 = getCcAddresses().iterator();
        while (it2.hasNext()) {
          email = it2.next().toString();
          getLog().info("Sending cc mail to " + email + "...");
          mailMsg.addCc(email, "");
        }
      }

      if (getBccAddresses() != null) {
        final Iterator it3 = getBccAddresses().iterator();
        while (it3.hasNext()) {
          email = it3.next().toString();
          getLog().info("Sending bcc mail to " + email + "...");
          mailMsg.addBcc(email, "");
        }
      }

      mailer.send(mailMsg);
      getLog().info("Sent...");
    } catch (IOException ioe) {
      throw new MojoExecutionException("Failed to send email.", ioe);
    } catch (MailSenderException e) {
      throw new MojoExecutionException("Failed to send email < " + email + " >", e);
    }
  }
  public void execute() throws MojoExecutionException {
    // Run only at the execution root
    if (runOnlyAtExecutionRoot && !isThisTheExecutionRoot()) {
      getLog()
          .info(
              "Skipping the announcement mail in this project because it's not the Execution Root");
    } else {
      File templateFile = new File(templateOutputDirectory, template);

      ConsoleLogger logger = new ConsoleLogger(Logger.LEVEL_INFO, "base");

      if (getLog().isDebugEnabled()) {
        logger.setThreshold(Logger.LEVEL_DEBUG);
      }

      mailer.enableLogging(logger);

      mailer.setSmtpHost(getSmtpHost());

      mailer.setSmtpPort(getSmtpPort());

      mailer.setSslMode(sslMode);

      if (username != null) {
        mailer.setUsername(username);
      }

      if (password != null) {
        mailer.setPassword(password);
      }

      mailer.initialize();

      if (getLog().isDebugEnabled()) {
        getLog().debug("fromDeveloperId: " + getFromDeveloperId());
      }

      if (templateFile.isFile()) {
        getLog().info("Connecting to Host: " + getSmtpHost() + ":" + getSmtpPort());

        sendMessage();
      } else {
        throw new MojoExecutionException("Announcement template " + templateFile + " not found...");
      }
    }
  }