private function sendPersonById(
    $mailer,
    $controller,
    $recipient_id,
    $preview = false)
  {

      // TODO: check if sent before !!!
      
     // $person = $recipient->getPerson();
      
    // echo( $recipient_id .' // '. memory_get_usage() .'<br>');


      $recipient = Doctrine_Core::getTable('dsClassLetterRecipient')->getOneJoined( $recipient_id );


      $to = ($preview) ? 
        array( sfContext::getInstance()->getUser()->getProfile()->getEmail() => sfContext::getInstance()->getUser()->getName() ): 
        array( $recipient->getPerson()->getEmail() => $recipient->getPerson()->getName() );
      
      $message = new dsEmailMessage('');
      
      // SUBJECT
      $subject_prefix = '';
      if ($preview)
        $subject_prefix = 'VORSCHAU: ';
            

    $arr = $this->parseEnrolment( $recipient->getEnrolment() );
    $body = $arr[0];
    $subject = $arr[1];


    // to catch swiftmailer exceptions
    try
      {

    $message
      ->setSubject( sprintf('%s%s', $subject_prefix, $subject ))
      ->setFrom( array( '*****@*****.**' => 'Downtownswing' ))
      ->setSender( '*****@*****.**')
      ->setReturnPath('*****@*****.**')
      ->setTo( $to );
      
      if (!$preview) {
        // mandrill 
        $message->getHeaders()->addTextHeader('X-MC-Tags', 'classletter, kickoff');
        $message->getHeaders()->addTextHeader('X-MC-Metadata', json_encode( array( 'letter_id' => $this->getId() )));
      }
        // $message->getHeaders()->addTextHeader('X-Mailjet-Campaign', 'ClassLetter.'.$this->id);
    
      $message->setBody( $body );

      // debug

      $mailer->send($message);

      if (!$preview) {
        $recipient->setDateTimeObject('sent_at', new DateTime() );
        $recipient->setEmail( $recipient->getPerson()->email );
        $recipient->setBody( $message->getBody() );
        $recipient->save();
      }

     }
      catch (Exception $e)
      {
      if (!$preview) {
        // TODO: set error
        $recipient->setSentAt( null );
        $recipient->save();
      }
      }

      //unset($body);

      $message->free( true );
      //unset($message);

      $recipient->free( true );
      //unset($recipient);

      return true;
  }
  public function sendRegistrationReceipt($mailer, $controller)
  {  

    $template = Doctrine_Core::getTable('dsEmailNotificationTemplate')->findOneByName( 'registration_receipt' );

    $template->setReplacements( $this->getReplacements() );
    list( $body, $subject ) = $template->parse();   

    $message = new dsEmailMessage('');
    
    //$profile = $this->getProfile();
    $message
      ->setSubject( $subject )
      ->setFrom( array('*****@*****.**' => 'Downtownswing'))
      ->setSender( '*****@*****.**')
      ->setReturnPath('*****@*****.**')
      ->setTo( array( $this->getEmail() => $this->getFullName() ));
    
    /* ->setBcc('*****@*****.**') */

    /*
    $variables = array(
        // 'sender' => $this->getUser()->getGuardUser()->getFirstName(),
        'name' => $this->getFirstName(),
        'class' => $this->getClass(),
        'registration' => $this
      );
    */

    $message->setBody( $body );

    // mandrill
    $message->getHeaders()->addTextHeader('X-MC-Tags', 'registration_receipt');

    $message->getHeaders()->addTextHeader('X-MC-Metadata', json_encode( array( 
      'registration_id' => $this->id ,
      'class_id'        => $this->class_id
      )));

    $mailer->send( $message );

    return true;       
  }