Example #1
0
 /**
  * Instantiates the requisite Mailer and returns it.
  *
  * @static
  * @access private
  * @param OutboundEmailConfiguration $config          required Must be an OutboundEmailConfiguration or a type that derives
  *                                                    from it.
  * @return mixed An object of one of the Mailers defined in $modeToMailerMap.
  * @throws MailerException
  */
 private static function buildMailer(OutboundEmailConfiguration $config)
 {
     $mode = $config->getMode();
     $strategy = static::getStrategy($mode);
     $mailer = null;
     if (is_null($strategy)) {
         throw new MailerException("Invalid Mailer: Could not find a strategy for mode '{$mode}'", MailerException::InvalidMailer);
     }
     if (class_exists($strategy)) {
         $mailer = new $strategy($config);
     }
     if (!$mailer instanceof $strategy) {
         throw new MailerException("Invalid Mailer: Could not find the strategy defined by class '{$strategy}'", MailerException::InvalidMailer);
     }
     return $mailer;
 }
 /**
  * @access private
  * @param User          $user           required
  * @param array         $configurations required
  * @param OutboundEmail $outboundEmail  required
  * @param Localization  $locale
  * @param string        $charset
  * @return OutboundEmailConfiguration
  */
 public static function buildOutboundEmailConfiguration(User $user, $configurations, $outboundEmail, Localization $locale = null, $charset = null)
 {
     $outboundEmailConfiguration = null;
     $mode = strtolower($outboundEmail->mail_sendtype);
     // setup the mailer's known configurations based on the type of mailer
     switch ($mode) {
         case self::MODE_SMTP:
             $outboundEmailConfiguration = new OutboundSmtpEmailConfiguration($user);
             $outboundEmailConfiguration->setHost($outboundEmail->mail_smtpserver);
             $outboundEmailConfiguration->setPort($outboundEmail->mail_smtpport);
             if ($outboundEmail->mail_smtpauth_req) {
                 // require authentication with the SMTP server
                 $outboundEmailConfiguration->setAuthenticationRequirement(true);
                 $outboundEmailConfiguration->setUsername($outboundEmail->mail_smtpuser);
                 $outboundEmailConfiguration->setPassword($outboundEmail->mail_smtppass);
             }
             // determine the appropriate encryption layer for the sending strategy
             if ($outboundEmail->mail_smtpssl == 1) {
                 $outboundEmailConfiguration->setSecurityProtocol(OutboundSmtpEmailConfiguration::SecurityProtocolSsl);
             } elseif ($outboundEmail->mail_smtpssl == 2) {
                 $outboundEmailConfiguration->setSecurityProtocol(OutboundSmtpEmailConfiguration::SecurityProtocolTls);
             }
             break;
         default:
             $outboundEmailConfiguration = new OutboundEmailConfiguration($user);
             break;
     }
     $outboundEmailConfiguration->setMode($mode);
     // hostname for SMTP HELO
     $hostname = !empty($GLOBALS['sugar_config']['helo_hostname']) ? $GLOBALS['sugar_config']['helo_hostname'] : $GLOBALS['sugar_config']['host_name'];
     $outboundEmailConfiguration->setHostname($hostname);
     if (!empty($configurations["config_id"])) {
         $outboundEmailConfiguration->setConfigId($configurations["config_id"]);
     }
     if (!empty($configurations["config_type"])) {
         $outboundEmailConfiguration->setConfigType($configurations["config_type"]);
     }
     if (!empty($outboundEmail->name)) {
         $outboundEmailConfiguration->setConfigName($outboundEmail->name);
     }
     if (!empty($configurations["inbox_id"])) {
         $outboundEmailConfiguration->setInboxId($configurations["inbox_id"]);
     }
     if (!empty($configurations["inbound_ids"])) {
         $outboundEmailConfiguration->setInboundIds($configurations["inbound_ids"]);
     }
     if (!empty($configurations["from_email"])) {
         $outboundEmailConfiguration->setFrom($configurations["from_email"], $configurations["from_name"]);
     }
     if (!empty($configurations["display_name"])) {
         $outboundEmailConfiguration->setDisplayName($configurations["display_name"]);
     }
     if (!empty($configurations["replyto_email"])) {
         $outboundEmailConfiguration->setReplyTo($configurations["replyto_email"], $configurations["replyto_name"]);
     }
     if (!is_bool($configurations["personal"])) {
         $configurations["personal"] = $configurations["personal"] ? true : false;
     }
     $outboundEmailConfiguration->setPersonal($configurations["personal"]);
     if (is_null($locale)) {
         $locale = $GLOBALS["locale"];
     }
     $outboundEmailConfiguration->setLocale($locale);
     if (is_null($charset)) {
         $charset = $locale->getPrecedentPreference("default_email_charset");
     }
     $outboundEmailConfiguration->setCharset($charset);
     return $outboundEmailConfiguration;
 }
 /**
  * @access public
  * @return array
  */
 public function toArray()
 {
     $fields = array("host" => $this->getHost(), "port" => $this->getPort(), "authenticate" => $this->isAuthenticationRequired(), "securityProtocol" => $this->getSecurityProtocol(), "username" => $this->getUsername(), "password" => $this->getPassword());
     return array_merge(parent::toArray(), $fields);
 }