/** * 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; }
/** * NotifyOwner * This will notify the list owner(s) of job runs. * This will send the appropriate message depending on the state of the job. * If the job is not set to notify the owner, this does nothing. * * @see emailssent * @see jobdetails * @see jobstatus * @see Email_API::ForgetEmail * @see GetUser * @see Email_API::Set * @see Email_API::Subject * @see Email_API::FromName * @see Email_API::FromAddress * @see Email_API::Multipart * @see Email_API::AddBody * @see Email_API::ClearAttachments * @see Email_API::ClearRecipients * @see Email_API::AddRecipient * @see Email_API::Send * @see Sendstudio_Functions::PrintTime * @see Sendstudio_Functions::FormatNumber * * @return Void Doesn't return anything. */ function NotifyOwner() { if (empty($this->jobdetails)) { return; } if (!$this->jobdetails['NotifyOwner']) { return; } if (is_null($this->jobstatus)) { return; } /** * If test mode is enabled, no point doing anything else. */ if (SENDSTUDIO_SEND_TEST_MODE) { return; } if (!class_exists('SS_Email_API', false)) { require_once SENDSTUDIO_API_DIRECTORY . DIRECTORY_SEPARATOR . 'ss_email.php'; } $notify_email = new SS_Email_API; $owner = GetUser($this->jobowner); // Check if each user have SMTP settings specified. // Otherwise use the global SMTP settings. if ($owner->smtpserver) { $notify_email->SetSmtp($owner->smtpserver, $owner->smtpusername, $owner->smtppassword, $owner->smtpport); } else { $notify_email->SetSmtp(SENDSTUDIO_SMTP_SERVER, SENDSTUDIO_SMTP_USERNAME, @base64_decode(SENDSTUDIO_SMTP_PASSWORD), SENDSTUDIO_SMTP_PORT); } $time = $this->sendstudio_functions->PrintTime(); /** * If the notify email subject or message are empty, create them. * This is mainly for backwards compatibility so the jobs_send.php file didn't need to be changed too much. */ if ($this->notify_email['subject'] == '' || $this->notify_email['message'] == '') { switch ($this->jobstatus) { case 'c': $subject = sprintf(GetLang('Job_Subject_Complete'), $this->newsletter['Subject']); if ($this->emailssent == 1) { $message = sprintf(GetLang('Job_Message_Complete_One'), $this->newsletter['Subject'], $time); } else { $message = sprintf(GetLang('Job_Message_Complete_Many'), $this->newsletter['Subject'], $time, $this->sendstudio_functions->FormatNumber($this->emailssent)); } break; case 'p': $subject = sprintf(GetLang('Job_Subject_Paused'), $this->newsletter['Subject']); if ($this->emailssent == 1) { $message = sprintf(GetLang('Job_Message_Paused_One'), $this->newsletter['Subject'], $time); } else { $message = sprintf(GetLang('Job_Message_Paused_Many'), $this->newsletter['Subject'], $time, $this->sendstudio_functions->FormatNumber($this->emailssent)); } break; default: $subject = sprintf(GetLang('Job_Subject_Started'), $this->newsletter['Subject']); $message = sprintf(GetLang('Job_Message_Started'), $this->newsletter['Subject'], $time); } $this->notify_email = array ( 'subject' => $subject, 'message' => $message ); } $subject = $this->notify_email['subject']; $message = $this->notify_email['message']; $notify_email->Set('Subject', $subject); $notify_email->Set('CharSet', SENDSTUDIO_CHARSET); if ($owner->fullname) { $notify_email->Set('FromName', $owner->fullname); } else { $notify_email->Set('FromName', GetLang('SendingSystem')); } if ($owner->emailaddress) { $notify_email->Set('FromAddress', $owner->emailaddress); } else { $notify_email->Set('FromAddress', GetLang('SendingSystem_From')); } $notify_email->Set('Multipart', false); $notify_email->AddBody('text', $message); $query = "SELECT listid, ownername, owneremail FROM " . SENDSTUDIO_TABLEPREFIX . "lists WHERE listid IN(" . implode(',', $this->jobdetails['Lists']) . ")"; $result = $this->Db->Query($query); while ($row = $this->Db->Fetch($result)) { $notify_email->AddRecipient($row['owneremail'], $row['ownername'], 't'); } $notify_email->Send(); $notify_email->ForgetEmail(); unset($notify_email); $this->notify_email['subject'] = ''; $this->notify_email['message'] = ''; }