/** Send the email. */
 public void sendEmail(Email outgoing) {
   LOG.trace("ENTER");
   outgoing.setStatus(Email.STATUS_OUTBOX);
   outbox.add(outgoing);
   if (emailListener != null) {
     emailListener.outgoingEmailEvent(null, outgoing);
   }
   LOG.debug("E-mail added to outbox. Size is [" + outbox.size() + "]");
   LOG.trace("EXIT");
 }
 public void run() {
   LOG.trace("ENTER");
   running = true;
   while (running) {
     Email email;
     while ((email = outbox.poll()) != null) {
       LOG.debug("Got e-mail [" + email + "] from outbox");
       try {
         LOG.debug(
             "Looking for a thread for this e-mail server ["
                 + email.getEmailFrom().getAccountServer()
                 + "]");
         if (serverHandlers.containsKey(email.getEmailFrom())) {
           LOG.debug("A Thread for the server already exists!");
           if (serverHandlers.get(email.getEmailFrom()).isAlive()) {
             LOG.debug("And it is alive! Adding this e-mail to the thread outbox.");
             serverHandlers.get(email.getEmailFrom()).sendEmail(email);
           } else {
             LOG.debug(
                 "And it is dead! Creating a new thread for server ["
                     + email.getEmailFrom().getAccountServer()
                     + "]...");
             EmailSender sender = new EmailSender(email.getEmailFrom(), this);
             sender.sendEmail(email);
             sender.start();
             serverHandlers.put(email.getEmailFrom(), sender);
           }
         } else {
           LOG.debug(
               "No thread found! Creating a new thread for server ["
                   + email.getEmailFrom().getAccountServer()
                   + "]...");
           EmailSender sender = new EmailSender(email.getEmailFrom(), this);
           sender.sendEmail(email);
           sender.start();
           serverHandlers.put(email.getEmailFrom(), sender);
         }
       } catch (Exception e) {
         // This exception may happens because the account was deleted.
         LOG.debug("Error retrieving account details", e);
       }
     }
     Utils.sleep_ignoreInterrupts(5000);
   }
   LOG.trace("EXIT");
 }