Exemplo n.º 1
0
 /**
  * SetupEmail
  * Sets up the email object for use.
  * If the email has been set up before, it sets the Email_API object to the cache version and returns.
  *
  * If it has not been set up before,
  * the newsletter is loaded into the email class (subject, htmlbody, textbody, attachments)
  *
  * If it's a partial setup (the flag passed in), once the content has been loaded into the Email_API object
  * the method returns.
  *
  * This is used to get custom field id's being used in the email campaigns
  * so they can be loaded in bulk.
  *
  * If it's not a partial setup, then it
  * - sets the appropriate smtp details
  * - loads attachments
  * - sets extra header information
  * - sets the email header details (bounce, reply-to, from details etc)
  * - after all of that, set the object into the email_objects cache for later use.
  *
  * @param Boolean $partial_setup Whether this is a partial setup or not. A partial set up is used to work out which custom fields are being used so they can be loaded in bulk.
  *
  * @uses Email_API
  * @uses email_objects
  * @uses newsletters
  * @uses _sending_newsletter
  * @uses SS_Email_API
  */
 private function SetupEmail($partial_setup = false)
 {
     if (isset($this->email_objects[$this->_sending_newsletter])) {
         $this->Email_API = $this->email_objects[$this->_sending_newsletter];
         return;
     }
     /**
      * Set up the email class
      * so we can get the custom fields we need to.
      */
     if (!isset($this->newsletters[$this->_sending_newsletter])) {
         return false;
     }
     $newsletter = $this->newsletters[$this->_sending_newsletter];
     $email_api = new SS_Email_API();
     if (SENDSTUDIO_SEND_TEST_MODE) {
         $email_api->TestMode = true;
     }
     $email_api->Set('Multipart', $this->jobdetails['Multipart']);
     $email_api->Set('Subject', $newsletter['Subject']);
     if ($this->jobdetails['Multipart']) {
         if ($newsletter['TextBody'] && $newsletter['HTMLBody'] && $newsletter['Format'] == 'b') {
             $sent_format = 'm';
         } else {
             $email_api->Set('Multipart', false);
         }
     }
     if ($newsletter['TextBody'] && in_array($newsletter['Format'], array('t', 'b'))) {
         $email_api->AddBody('text', $newsletter['TextBody']);
         $email_api->AppendBody('text', $this->user->Get('textfooter'));
         $email_api->AppendBody('text', stripslashes(SENDSTUDIO_TEXTFOOTER));
     }
     if ($newsletter['HTMLBody'] && in_array($newsletter['Format'], array('h', 'b'))) {
         $email_api->AddBody('html', $newsletter['HTMLBody']);
         $email_api->AppendBody('html', $this->user->Get('htmlfooter'));
         $email_api->AppendBody('html', stripslashes(SENDSTUDIO_HTMLFOOTER));
     }
     if ($partial_setup) {
         $this->Email_API = $email_api;
         return;
     }
     $email_api->ClearRecipients();
     $email_api->SetSmtp(SENDSTUDIO_SMTP_SERVER, SENDSTUDIO_SMTP_USERNAME, @base64_decode(SENDSTUDIO_SMTP_PASSWORD), SENDSTUDIO_SMTP_PORT);
     $email_api->Set('statid', $this->statids[$this->_sending_newsletter]);
     $email_api->Set('listids', $this->jobdetails['Lists']);
     if (SENDSTUDIO_FORCE_UNSUBLINK) {
         $email_api->ForceLinkChecks(true);
     }
     $email_api->TrackOpens(true);
     $email_api->TrackLinks(true);
     $email_api->Set('CharSet', $this->jobdetails['Charset']);
     if (!SENDSTUDIO_SAFE_MODE) {
         $email_api->Set('imagedir', TEMP_DIRECTORY . '/send.' . $this->_jobid . '.' . $this->_queueid);
     } else {
         $email_api->Set('imagedir', TEMP_DIRECTORY . '/send');
     }
     // clear out the attachments just to be safe.
     $email_api->ClearAttachments();
     if ($newsletter['Attachments']) {
         $path = $newsletter['Attachments']['path'];
         $files = $newsletter['Attachments']['filelist'];
         foreach ($files as $p => $file) {
             $email_api->AddAttachment($path . '/' . $file);
         }
     }
     $email_api->Set('FromName', $this->jobdetails['SendFromName']);
     $email_api->Set('FromAddress', $this->jobdetails['SendFromEmail']);
     $email_api->Set('ReplyTo', $this->jobdetails['ReplyToEmail']);
     $email_api->Set('BounceAddress', $this->jobdetails['BounceEmail']);
     $email_api->Set('EmbedImages', $this->jobdetails['EmbedImages']);
     $email_api->Set('SentBy', $this->user->Get('userid'));
     if ($this->user->smtpserver) {
         $email_api->SetSmtp($this->user->smtpserver, $this->user->smtpusername, $this->user->smtppassword, $this->user->smtpport);
     }
     $this->email_objects[$this->_sending_newsletter] = $email_api;
     $this->Email_API = $email_api;
 }