private function sendMail($templateId, Gpf_Data_Record $userRecord)
 {
     $user = new Pap_Common_User();
     $user->fillFromRecord($userRecord);
     $user->setPassword($userRecord->get('password'));
     $template = new Pap_Mail_MassMailTemplate();
     $template->setTemplateId($templateId);
     $template->setUser($user);
     $template->addRecipient($user->getEmail());
     $template->send();
 }
    private function sendMail(Gpf_Db_MailTemplate $dbTemplate, Gpf_Rpc_Form $form) {
        $user = new Pap_Common_User();
        $user->setId($form->getFieldValue('userid'));
        $user->load();

        $template = new Pap_Mail_MassMailTemplate();
        $template->setTemplateId($dbTemplate->getId());
        $template->setUser($user);
        $template->addRecipient($user->getEmail());
        $template->send();
    }
 private function sendCustomEmails($params){
     
     $delaySetting = Gpf_Settings::get(Pap_Settings::AFF_SEND_EMAILS_PER_MINUTE_SETTING_NAME);
     $i=0;
     
     $recipients = explode(",",$params[self::CUSTOM_MAILS]);
     $template = new Pap_Mail_MassMailTemplate();
     $template->setTemplateId($params[self::TEMPLATE_ID]);
     if($params[self::SENDER] != "") {
         $template->setFromEmail($params[self::SENDER]);
     }
     
     foreach($recipients as $emailAddress){
         $this->interruptIfMemoryFull();
         if ($this->isPending($i, $this->_("Scheduled $emailAddress mail"))) {
         
             $this->changeProgress($i, $this->_("Scheduled $emailAddress mail"));
             $this->checkInterruption();
             
             $template->clearRecipients();
             $template->addRecipient($emailAddress);
             
             $template->send(false, (int)($i/$delaySetting));
             $this->setDone();
         }
         $i++;
     }
 }