예제 #1
0
 /**
  * Create a new mailer to send any mail from the application.
  *
  * Note: The mailer is opened in persistent mode.
  *
  * Note: You probably don't want to call this directly. Get a reference
  * to the mailer through the container.
  *
  * @return Mail
  */
 public static function createMailer()
 {
     $mailingInfo = Civi::settings()->get('mailing_backend');
     if ($mailingInfo['outBound_option'] == CRM_Mailing_Config::OUTBOUND_OPTION_REDIRECT_TO_DB || defined('CIVICRM_MAILER_SPOOL') && CIVICRM_MAILER_SPOOL) {
         $mailer = self::_createMailer('CRM_Mailing_BAO_Spool', array());
     } elseif ($mailingInfo['outBound_option'] == CRM_Mailing_Config::OUTBOUND_OPTION_SMTP) {
         if ($mailingInfo['smtpServer'] == '' || !$mailingInfo['smtpServer']) {
             CRM_Core_Error::debug_log_message(ts('There is no valid smtp server setting. Click <a href=\'%1\'>Administer >> System Setting >> Outbound Email</a> to set the SMTP Server.', array(1 => CRM_Utils_System::url('civicrm/admin/setting/smtp', 'reset=1'))));
             CRM_Core_Error::fatal(ts('There is no valid smtp server setting. Click <a href=\'%1\'>Administer >> System Setting >> Outbound Email</a> to set the SMTP Server.', array(1 => CRM_Utils_System::url('civicrm/admin/setting/smtp', 'reset=1'))));
         }
         $params['host'] = $mailingInfo['smtpServer'] ? $mailingInfo['smtpServer'] : 'localhost';
         $params['port'] = $mailingInfo['smtpPort'] ? $mailingInfo['smtpPort'] : 25;
         if ($mailingInfo['smtpAuth']) {
             $params['username'] = $mailingInfo['smtpUsername'];
             $params['password'] = CRM_Utils_Crypt::decrypt($mailingInfo['smtpPassword']);
             $params['auth'] = TRUE;
         } else {
             $params['auth'] = FALSE;
         }
         // set the localhost value, CRM-3153
         $params['localhost'] = CRM_Utils_Array::value('SERVER_NAME', $_SERVER, 'localhost');
         // also set the timeout value, lets set it to 30 seconds
         // CRM-7510
         $params['timeout'] = 30;
         // CRM-9349
         $params['persist'] = TRUE;
         $mailer = self::_createMailer('smtp', $params);
     } elseif ($mailingInfo['outBound_option'] == CRM_Mailing_Config::OUTBOUND_OPTION_SENDMAIL) {
         if ($mailingInfo['sendmail_path'] == '' || !$mailingInfo['sendmail_path']) {
             CRM_Core_Error::debug_log_message(ts('There is no valid sendmail path setting. Click <a href=\'%1\'>Administer >> System Setting >> Outbound Email</a> to set the sendmail server.', array(1 => CRM_Utils_System::url('civicrm/admin/setting/smtp', 'reset=1'))));
             CRM_Core_Error::fatal(ts('There is no valid sendmail path setting. Click <a href=\'%1\'>Administer >> System Setting >> Outbound Email</a> to set the sendmail server.', array(1 => CRM_Utils_System::url('civicrm/admin/setting/smtp', 'reset=1'))));
         }
         $params['sendmail_path'] = $mailingInfo['sendmail_path'];
         $params['sendmail_args'] = $mailingInfo['sendmail_args'];
         $mailer = self::_createMailer('sendmail', $params);
     } elseif ($mailingInfo['outBound_option'] == CRM_Mailing_Config::OUTBOUND_OPTION_MAIL) {
         $mailer = self::_createMailer('mail', array());
     } elseif ($mailingInfo['outBound_option'] == CRM_Mailing_Config::OUTBOUND_OPTION_MOCK) {
         $mailer = self::_createMailer('mock', array());
     } elseif ($mailingInfo['outBound_option'] == CRM_Mailing_Config::OUTBOUND_OPTION_DISABLED) {
         CRM_Core_Error::debug_log_message(ts('Outbound mail has been disabled. Click <a href=\'%1\'>Administer >> System Setting >> Outbound Email</a> to set the OutBound Email.', array(1 => CRM_Utils_System::url('civicrm/admin/setting/smtp', 'reset=1'))));
         CRM_Core_Session::setStatus(ts('Outbound mail has been disabled. Click <a href=\'%1\'>Administer >> System Setting >> Outbound Email</a> to set the OutBound Email.', array(1 => CRM_Utils_System::url('civicrm/admin/setting/smtp', 'reset=1'))));
     } else {
         CRM_Core_Error::debug_log_message(ts('There is no valid SMTP server Setting Or SendMail path setting. Click <a href=\'%1\'>Administer >> System Setting >> Outbound Email</a> to set the OutBound Email.', array(1 => CRM_Utils_System::url('civicrm/admin/setting/smtp', 'reset=1'))));
         CRM_Core_Session::setStatus(ts('There is no valid SMTP server Setting Or sendMail path setting. Click <a href=\'%1\'>Administer >> System Setting >> Outbound Email</a> to set the OutBound Email.', array(1 => CRM_Utils_System::url('civicrm/admin/setting/smtp', 'reset=1'))));
         CRM_Core_Error::debug_var('mailing_info', $mailingInfo);
     }
     return $mailer;
 }
예제 #2
0
파일: Config.php 프로젝트: ksecor/civicrm
 /**
  * retrieve a mailer to send any mail from the applciation
  *
  * @param
  * @access private
  * @return object
  */
 static function &getMailer()
 {
     if (!isset(self::$_mail)) {
         require_once "CRM/Core/BAO/Preferences.php";
         $mailingInfo =& CRM_Core_BAO_Preferences::mailingPreferences();
         if (defined('CIVICRM_MAILER_SPOOL') && CIVICRM_MAILER_SPOOL) {
             require_once 'CRM/Mailing/BAO/Spool.php';
             self::$_mail = new CRM_Mailing_BAO_Spool();
         } elseif ($mailingInfo['outBound_option'] == 0) {
             if ($mailingInfo['smtpServer'] == '' || !$mailingInfo['smtpServer']) {
                 CRM_Core_Error::fatal(ts('There is no valid smtp server setting. Click <a href=\'%1\'>Administer CiviCRM >> Global Settings</a> to set the SMTP Server.', array(1 => CRM_Utils_System::url('civicrm/admin/setting', 'reset=1'))));
             }
             $params['host'] = $mailingInfo['smtpServer'] ? $mailingInfo['smtpServer'] : 'localhost';
             $params['port'] = $mailingInfo['smtpPort'] ? $mailingInfo['smtpPort'] : 25;
             if ($mailingInfo['smtpAuth']) {
                 require_once 'CRM/Utils/Crypt.php';
                 $params['username'] = $mailingInfo['smtpUsername'];
                 $params['password'] = CRM_Utils_Crypt::decrypt($mailingInfo['smtpPassword']);
                 $params['auth'] = true;
             } else {
                 $params['auth'] = false;
             }
             // set the localhost value, CRM-3153
             $params['localhost'] = $_SERVER['SERVER_NAME'];
             self::$_mail =& Mail::factory('smtp', $params);
         } elseif ($mailingInfo['outBound_option'] == 1) {
             if ($mailingInfo['sendmail_path'] == '' || !$mailingInfo['sendmail_path']) {
                 CRM_Core_Error::fatal(ts('There is no valid sendmail path setting. Click <a href=\'%1\'>Administer CiviCRM >> Global Settings</a> to set the Sendmail Server.', array(1 => CRM_Utils_System::url('civicrm/admin/setting', 'reset=1'))));
             }
             $params['sendmail_path'] = $mailingInfo['sendmail_path'];
             $params['sendmail_args'] = $mailingInfo['sendmail_args'];
             self::$_mail =& Mail::factory('sendmail', $params);
         } else {
             CRM_Core_Session::setStatus(ts('There is no valid SMTP server Setting Or SendMail path setting. Click <a href=\'%1\'>Administer CiviCRM >> Global Settings</a> to set the OutBound Email.', array(1 => CRM_Utils_System::url('civicrm/admin/setting', 'reset=1'))));
         }
     }
     return self::$_mail;
 }
예제 #3
0
 function upgrade($rev)
 {
     $upgrade =& new CRM_Upgrade_Form();
     //Run the SQL file
     $upgrade->processSQL($rev);
     // fix for CRM-5162
     // we need to encrypt all smtpPasswords if present
     require_once "CRM/Core/DAO/Preferences.php";
     $mailingDomain =& new CRM_Core_DAO_Preferences();
     $mailingDomain->find();
     while ($mailingDomain->fetch()) {
         if ($mailingDomain->mailing_backend) {
             $values = unserialize($mailingDomain->mailing_backend);
             if (isset($values['smtpPassword'])) {
                 require_once 'CRM/Utils/Crypt.php';
                 $values['smtpPassword'] = CRM_Utils_Crypt::encrypt($values['smtpPassword']);
                 $mailingDomain->mailing_backend = serialize($values);
                 $mailingDomain->save();
             }
         }
     }
     require_once "CRM/Core/DAO/Domain.php";
     $domain =& new CRM_Core_DAO_Domain();
     $domain->selectAdd();
     $domain->selectAdd('config_backend');
     $domain->find(true);
     if ($domain->config_backend) {
         $defaults = unserialize($domain->config_backend);
         if ($dateFormat = CRM_Utils_Array::value('dateformatQfDate', $defaults)) {
             $dateFormatArray = explode(" ", $dateFormat);
             //replace new date format based on previous month format
             //%b month name [abbreviated]
             //%B full month name ('January'..'December')
             //%m decimal number, 0-padded ('01'..'12')
             if ($dateFormat == '%b %d %Y') {
                 $defaults['dateInputFormat'] = 'mm/dd/yy';
             } else {
                 if ($dateFormat == '%d-%b-%Y') {
                     $defaults['dateInputFormat'] = 'dd-mm-yy';
                 } else {
                     if (in_array('%b', $dateFormatArray)) {
                         $defaults['dateInputFormat'] = 'M d, yy';
                     } else {
                         if (in_array('%B', $dateFormatArray)) {
                             $defaults['dateInputFormat'] = 'MM d, yy';
                         } else {
                             $defaults['dateInputFormat'] = 'mm/dd/yy';
                         }
                     }
                 }
             }
         }
         // %p - lowercase ante/post meridiem ('am', 'pm')
         // %P - uppercase ante/post meridiem ('AM', 'PM')
         if ($dateTimeFormat = CRM_Utils_Array::value('dateformatQfDatetime', $defaults)) {
             $defaults['timeInputFormat'] = 2;
             $dateTimeFormatArray = explode(" ", $dateFormat);
             if (in_array('%P', $dateTimeFormatArray) || in_array('%p', $dateTimeFormatArray)) {
                 $defaults['timeInputFormat'] = 1;
             }
             unset($defaults['dateformatQfDatetime']);
         }
         unset($defaults['dateformatQfDate']);
         unset($defaults['dateformatTime']);
         require_once "CRM/Core/BAO/Setting.php";
         CRM_Core_BAO_Setting::add($defaults);
     }
     $sql = "SELECT id, form_values FROM civicrm_report_instance";
     $instDAO = CRM_Core_DAO::executeQuery($sql);
     while ($instDAO->fetch()) {
         $fromVal = @unserialize($instDAO->form_values);
         foreach ((array) $fromVal as $key => $value) {
             if (strstr($key, '_relative')) {
                 $elementName = substr($key, 0, strlen($key) - strlen('_relative'));
                 $fromNamekey = $elementName . '_from';
                 $toNamekey = $elementName . '_to';
                 $fromNameVal = $fromVal[$fromNamekey];
                 $toNameVal = $fromVal[$toNamekey];
                 //check 'choose date range' is set
                 if ($value == '0') {
                     if (CRM_Utils_Date::isDate($fromNameVal)) {
                         $fromDate = CRM_Utils_Date::setDateDefaults(CRM_Utils_Date::format($fromNameVal));
                         $fromNameVal = $fromDate[0];
                     } else {
                         $fromNameVal = '';
                     }
                     if (CRM_Utils_Date::isDate($toNameVal)) {
                         $toDate = CRM_Utils_Date::setDateDefaults(CRM_Utils_Date::format($toNameVal));
                         $toNameVal = $toDate[0];
                     } else {
                         $toNameVal = '';
                     }
                 } else {
                     $fromNameVal = '';
                     $toNameVal = '';
                 }
                 $fromVal[$fromNamekey] = $fromNameVal;
                 $fromVal[$toNamekey] = $toNameVal;
                 continue;
             }
         }
         $fromVal = serialize($fromVal);
         $updateSQL = "UPDATE civicrm_report_instance SET form_values = '{$fromVal}' WHERE id = {$instDAO->id}";
         CRM_Core_DAO::executeQuery($updateSQL);
     }
     $customFieldSQL = "SELECT id, date_format FROM civicrm_custom_field WHERE data_type = 'Date' ";
     $customDAO = CRM_Core_DAO::executeQuery($customFieldSQL);
     while ($customDAO->fetch()) {
         $datePartKey = $dateParts = explode(CRM_Core_DAO::VALUE_SEPARATOR, $customDAO->date_format);
         $dateParts = array_combine($datePartKey, $dateParts);
         $year = CRM_Utils_Array::value('Y', $dateParts);
         $month = CRM_Utils_Array::value('M', $dateParts);
         $date = CRM_Utils_Array::value('d', $dateParts);
         $hour = CRM_Utils_Array::value('h', $dateParts);
         $minute = CRM_Utils_Array::value('i', $dateParts);
         $timeFormat = CRM_Utils_Array::value('A', $dateParts);
         $newDateFormat = 'mm/dd/yy';
         if ($year && $month && $date) {
             $newDateFormat = 'mm/dd/yy';
         } else {
             if (!$year && $month && $date) {
                 $newDateFormat = 'mm/dd';
             }
         }
         $newTimeFormat = 'NULL';
         if ($timeFormat && $hour == 'h') {
             $newTimeFormat = 1;
         } else {
             if ($hour) {
                 $newTimeFormat = 2;
             }
         }
         $updateSQL = "UPDATE civicrm_custom_field SET date_format = '{$newDateFormat}', time_format = {$newTimeFormat} WHERE id = {$customDAO->id}";
         CRM_Core_DAO::executeQuery($updateSQL);
     }
     $template =& CRM_Core_Smarty::singleton();
     $afterUpgradeMessage = '';
     if ($afterUpgradeMessage = $template->get_template_vars('afterUpgradeMessage')) {
         $afterUpgradeMessage .= "<br/><br/>";
     }
     $afterUpgradeMessage .= ts("Date Input Format has been set to %1 format. If you want to use a different format please check Administer CiviCRM &raquo; Global Settings &raquo; Date Formats.", array(1 => $defaults['dateInputFormat']));
     $template->assign('afterUpgradeMessage', $afterUpgradeMessage);
 }
 /**
  * This function sets the default values for the form.
  * default values are retrieved from the database
  *
  * @access public
  *
  * @return None
  */
 function setDefaultValues()
 {
     if (!$this->_defaults) {
         $this->_defaults = array();
         $mailingBackend = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME, 'mandrill_smtp_settings');
         if (!empty($mailingBackend)) {
             $this->_defaults = $mailingBackend;
             if (!empty($this->_defaults['smtpPassword'])) {
                 $this->_defaults['smtpPassword'] = CRM_Utils_Crypt::decrypt($this->_defaults['smtpPassword']);
             }
         }
         $mandrillSecret = CRM_Core_OptionGroup::values('mandrill_secret', TRUE);
         $this->_defaults['mandril_post_url'] = CRM_Utils_System::url('civicrm/ajax/mte/callback', "mandrillSecret={$mandrillSecret['Secret Code']}", TRUE, NULL, FALSE, TRUE);
     }
     return $this->_defaults;
 }
예제 #5
0
 /**
  * Set default values for the form.
  */
 public function setDefaultValues()
 {
     if (!$this->_defaults) {
         $this->_defaults = array();
         $mailingBackend = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME, 'mailing_backend');
         if (!empty($mailingBackend)) {
             $this->_defaults = $mailingBackend;
             if (!empty($this->_defaults['smtpPassword'])) {
                 $this->_defaults['smtpPassword'] = CRM_Utils_Crypt::decrypt($this->_defaults['smtpPassword']);
             }
         } else {
             if (!isset($this->_defaults['smtpServer'])) {
                 $this->_defaults['smtpServer'] = 'localhost';
                 $this->_defaults['smtpPort'] = 25;
                 $this->_defaults['smtpAuth'] = 0;
             }
             if (!isset($this->_defaults['sendmail_path'])) {
                 $this->_defaults['sendmail_path'] = '/usr/sbin/sendmail';
                 $this->_defaults['sendmail_args'] = '-i';
             }
         }
     }
     return $this->_defaults;
 }
예제 #6
0
파일: Smtp.php 프로젝트: bhirsch/voipdev
 /**
  * This function sets the default values for the form.
  * default values are retrieved from the database
  * 
  * @access public
  * @return None
  */
 function setDefaultValues()
 {
     if (!$this->_defaults) {
         $this->_defaults = array();
         require_once "CRM/Core/DAO/Preferences.php";
         $mailingDomain =& new CRM_Core_DAO_Preferences();
         $mailingDomain->find(true);
         if ($mailingDomain->mailing_backend) {
             $this->_defaults = unserialize($mailingDomain->mailing_backend);
             if (!empty($this->_defaults['smtpPassword'])) {
                 require_once 'CRM/Utils/Crypt.php';
                 $this->_defaults['smtpPassword'] = CRM_Utils_Crypt::decrypt($this->_defaults['smtpPassword']);
             }
         } else {
             if (!isset($this->_defaults['smtpServer'])) {
                 $this->_defaults['smtpServer'] = 'localhost';
                 $this->_defaults['smtpPort'] = 25;
                 $this->_defaults['smtpAuth'] = 0;
             }
             if (!isset($this->_defaults['sendmail_path'])) {
                 $this->_defaults['sendmail_path'] = '/usr/sbin/sendmail';
                 $this->_defaults['sendmail_args'] = '-i';
             }
         }
     }
     return $this->_defaults;
 }
예제 #7
0
파일: ThreeOne.php 프로젝트: ksecor/civicrm
 function upgrade($rev)
 {
     $upgrade =& new CRM_Upgrade_Form();
     //Run the SQL file
     $upgrade->processSQL($rev);
     // fix for CRM-5162
     // we need to encrypt all smtpPasswords if present
     require_once "CRM/Core/DAO/Preferences.php";
     $mailingDomain =& new CRM_Core_DAO_Preferences();
     $mailingDomain->find();
     while ($mailingDomain->fetch()) {
         if ($mailingDomain->mailing_backend) {
             $values = unserialize($mailingDomain->mailing_backend);
             if (isset($values['smtpPassword'])) {
                 require_once 'CRM/Utils/Crypt.php';
                 $values['smtpPassword'] = CRM_Utils_Crypt::encrypt($values['smtpPassword']);
                 $mailingDomain->mailing_backend = setialize($values);
                 $mailingDomain->save();
             }
         }
     }
     require_once "CRM/Core/DAO/Domain.php";
     $domain =& new CRM_Core_DAO_Domain();
     $domain->selectAdd();
     $domain->selectAdd('config_backend');
     $domain->find(true);
     if ($domain->config_backend) {
         $defaults = unserialize($domain->config_backend);
         if ($dateFormat = $defaults['dateformatQfDate']) {
             $dateFormatArray = explode(" ", $dateFormat);
             //replace new date format based on previous month format
             //%b month name [abbreviated]
             //%B full month name ('January'..'December')
             //%m decimal number, 0-padded ('01'..'12')
             if (in_array('%b', $dateFormatArray)) {
                 $defaults['dateInputFormat'] = 'd M, y';
             } else {
                 if (in_array('%B', $dateFormatArray)) {
                     $defaults['dateInputFormat'] = 'd MM, y';
                 } else {
                     $defaults['dateInputFormat'] = 'mm/dd/yy';
                 }
             }
         }
         //Need to fix
         // %p - lowercase ante/post meridiem ('am', 'pm')
         // %P - uppercase ante/post meridiem ('AM', 'PM')
         $defaults['timeInputFormat'] = 1;
         unset($defaults['dateformatQfDate']);
         unset($defaults['dateformatQfDatetime']);
         unset($defaults['dateformatTime']);
         require_once "CRM/Core/BAO/Setting.php";
         CRM_Core_BAO_Setting::add($defaults);
     }
     $template =& CRM_Core_Smarty::singleton();
     $afterUpgradeMessage = '';
     if ($afterUpgradeMessage = $template->get_template_vars('afterUpgradeMessage')) {
         $afterUpgradeMessage .= "<br/><br/>";
     }
     $afterUpgradeMessage .= ts("Most of the Date Format has been changed to mm/dd/yy format. If you want to use a different format please check Date settings");
     $template->assign('afterUpgradeMessage', $afterUpgradeMessage);
 }
예제 #8
0
파일: ams.php 프로젝트: scardinius/ams
/**
 * Implements hook_civicrm_alterMailer().
 *
 * @param $mailer
 * @param $driver
 * @param $params
 */
function ams_civicrm_alterMailer(&$mailer, $driver, $params)
{
    $session = CRM_Core_Session::singleton();
    $ams = $session->get('ams', 'ams');
    if ($ams) {
        $name = 'mailing_backend_alternate' . (int) $ams;
        $setting = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME, $name);
        if ($setting['outBound_option'] == CRM_Mailing_Config::OUTBOUND_OPTION_SMTP) {
            $params['host'] = $setting['smtpServer'] ? $setting['smtpServer'] : 'localhost';
            $params['port'] = $setting['smtpPort'] ? $setting['smtpPort'] : 25;
            $mailer->host = $params['host'];
            $mailer->port = $params['port'];
            if ($setting['smtpAuth']) {
                $params['username'] = $setting['smtpUsername'];
                $params['password'] = CRM_Utils_Crypt::decrypt($setting['smtpPassword']);
                $params['auth'] = TRUE;
                $mailer->username = $params['username'];
                $mailer->password = $params['password'];
            } else {
                $params['auth'] = FALSE;
            }
            $mailer->auth = $params['auth'];
        }
    }
}
예제 #9
0
 /**
  * Set default values for the form.
  */
 public function setDefaultValues()
 {
     if (!$this->_defaults) {
         $this->_defaults = array();
         $mailingBackend = Civi::settings()->get('mailing_backend');
         if (!empty($mailingBackend)) {
             $this->_defaults = $mailingBackend;
             if (!empty($this->_defaults['smtpPassword'])) {
                 $this->_defaults['smtpPassword'] = CRM_Utils_Crypt::decrypt($this->_defaults['smtpPassword']);
             }
         } else {
             if (!isset($this->_defaults['smtpServer'])) {
                 $this->_defaults['smtpServer'] = 'localhost';
                 $this->_defaults['smtpPort'] = 25;
                 $this->_defaults['smtpAuth'] = 0;
             }
             if (!isset($this->_defaults['sendmail_path'])) {
                 $this->_defaults['sendmail_path'] = '/usr/sbin/sendmail';
                 $this->_defaults['sendmail_args'] = '-i';
             }
         }
     }
     return $this->_defaults;
 }
예제 #10
0
function mte_getmailer(&$mailer, &$params = array())
{
    $mailingBackend = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME, 'mandrill_smtp_settings');
    if (CRM_Utils_array::value('is_active', $mailingBackend)) {
        $params['host'] = $mailingBackend['smtpServer'];
        $params['port'] = $mailingBackend['smtpPort'];
        $params['username'] = trim($mailingBackend['smtpUsername']);
        $params['password'] = CRM_Utils_Crypt::decrypt($mailingBackend['smtpPassword']);
        $params['auth'] = $mailingBackend['smtpAuth'] ? TRUE : FALSE;
        $mailer = Mail::factory('smtp', $params);
        CRM_Core_Smarty::singleton()->assign('alterMailer', 0);
    }
}
예제 #11
0
 /**
  * retrieve a mailer to send any mail from the applciation
  *
  * @param boolean $persist open a persistent smtp connection, should speed up mailings
  *
  * @access private
  *
  * @return object
  */
 static function &getMailer($persist = FALSE)
 {
     if (!isset(self::$_mail)) {
         $mailingInfo = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME, 'mailing_backend');
         if (defined('CIVICRM_MAILER_SPOOL') && CIVICRM_MAILER_SPOOL) {
             self::$_mail = new CRM_Mailing_BAO_Spool();
         } elseif ($mailingInfo['outBound_option'] == 0) {
             if ($mailingInfo['smtpServer'] == '' || !$mailingInfo['smtpServer']) {
                 CRM_Core_Error::fatal(ts('There is no valid smtp server setting. Click <a href=\'%1\'>Administer CiviCRM >> Global Settings</a> to set the SMTP Server.', array(1 => CRM_Utils_System::url('civicrm/admin/setting', 'reset=1'))));
             }
             $params['host'] = $mailingInfo['smtpServer'] ? $mailingInfo['smtpServer'] : 'localhost';
             $params['port'] = $mailingInfo['smtpPort'] ? $mailingInfo['smtpPort'] : 25;
             if ($mailingInfo['smtpAuth']) {
                 $params['username'] = $mailingInfo['smtpUsername'];
                 $params['password'] = CRM_Utils_Crypt::decrypt($mailingInfo['smtpPassword']);
                 $params['auth'] = TRUE;
             } else {
                 $params['auth'] = FALSE;
             }
             // set the localhost value, CRM-3153
             $params['localhost'] = CRM_Utils_Array::value('SERVER_NAME', $_SERVER, 'localhost');
             // also set the timeout value, lets set it to 30 seconds
             // CRM-7510
             $params['timeout'] = 30;
             // CRM-9349
             $params['persist'] = $persist;
             self::$_mail = Mail::factory('smtp', $params);
         } elseif ($mailingInfo['outBound_option'] == 1) {
             if ($mailingInfo['sendmail_path'] == '' || !$mailingInfo['sendmail_path']) {
                 CRM_Core_Error::fatal(ts('There is no valid sendmail path setting. Click <a href=\'%1\'>Administer CiviCRM >> Global Settings</a> to set the Sendmail Server.', array(1 => CRM_Utils_System::url('civicrm/admin/setting', 'reset=1'))));
             }
             $params['sendmail_path'] = $mailingInfo['sendmail_path'];
             $params['sendmail_args'] = $mailingInfo['sendmail_args'];
             self::$_mail = Mail::factory('sendmail', $params);
         } elseif ($mailingInfo['outBound_option'] == 3) {
             $params = array();
             self::$_mail = Mail::factory('mail', $params);
         } elseif ($mailingInfo['outBound_option'] == 4) {
             self::$_mail = Mail::factory('mock', $params);
         } else {
             CRM_Core_Session::setStatus(ts('There is no valid SMTP server Setting Or SendMail path setting. Click <a href=\'%1\'>Administer CiviCRM >> Global Settings</a> to set the OutBound Email.', array(1 => CRM_Utils_System::url('civicrm/admin/setting', 'reset=1'))));
         }
     }
     return self::$_mail;
 }