Ejemplo n.º 1
0
 /**
  * Send mail message handler.
  *
  * @param array $params parameters
  * @return bool true on success
  */
 public function handleSendMailMessage($params)
 {
     $provider = $this->Setting->getValueByName(MAIL_PROVIDER_KEY, $this->moduleName);
     if ($provider === MAIL_PROVIDER_APP_ENGINE) {
         $service = new Midas_Service_AppEngine_Mail();
         $transport = new Midas_Mail_Transport_Service($service);
     } elseif ($provider === MAIL_PROVIDER_SEND_GRID) {
         $username = $this->Setting->getValueByName(MAIL_SEND_GRID_USERNAME_KEY, $this->moduleName);
         $password = $this->Setting->getValueByName(MAIL_SEND_GRID_PASSWORD_KEY, $this->moduleName);
         $service = new Midas_Service_SendGrid_Mail($username, $password);
         $transport = new Midas_Mail_Transport_Service($service);
     } elseif ($provider === MAIL_PROVIDER_SMTP) {
         $host = $this->Setting->getValueByName(MAIL_SMTP_HOST_KEY, $this->moduleName);
         $port = $this->Setting->getValueByName(MAIL_SMTP_PORT_KEY, $this->moduleName);
         $ssl = $this->Setting->getValueByName(MAIL_SMTP_USE_SSL_KEY, $this->moduleName);
         $username = $this->Setting->getValueByName(MAIL_SMTP_USERNAME_KEY, $this->moduleName);
         $password = $this->Setting->getValueByName(MAIL_SMTP_PASSWORD_KEY, $this->moduleName);
         $config = array();
         if (!empty($port)) {
             $config['port'] = $port;
         }
         if ($ssl === '1') {
             $config['ssl'] = 'tls';
         }
         if (!empty($username) && !empty($password)) {
             $config['auth'] = 'login';
             $config['username'] = $username;
             $config['password'] = $password;
         }
         $transport = new Zend_Mail_Transport_Smtp($host, $config);
     } else {
         $transport = new Zend_Mail_Transport_Sendmail();
     }
     $mail = new Midas_Mail();
     $mail->setFrom(htmlspecialchars($this->Setting->getValueByName(MAIL_FROM_ADDRESS_KEY, $this->moduleName), ENT_QUOTES, 'UTF-8'));
     if (isset($params['bcc'])) {
         $mail->addBcc(htmlspecialchars($params['bcc'], ENT_QUOTES, 'UTF-8'));
     }
     if (isset($params['cc'])) {
         $mail->addCc(htmlspecialchars($params['cc'], ENT_QUOTES, 'UTF-8'));
     }
     if (isset($params['html'])) {
         $mail->setBodyHtml($params['html']);
     }
     if (isset($params['subject'])) {
         $mail->setSubject(htmlspecialchars($params['subject'], ENT_QUOTES, 'UTF-8'));
     }
     if (isset($params['text'])) {
         $mail->setBodyText(htmlspecialchars($params['text'], ENT_QUOTES, 'UTF-8'));
     }
     if (isset($params['to'])) {
         $mail->addTo(htmlspecialchars($params['to'], ENT_QUOTES, 'UTF-8'));
     }
     try {
         $mail->send($transport);
     } catch (Zend_Exception $exception) {
         return false;
     }
     return true;
 }
Ejemplo n.º 2
0
 /**
  * Send the mail.
  *
  * @param Midas_Mail $mail mail instance
  * @throws Midas_Service_AppEngine_Exception
  */
 public function sendMail(Midas_Mail $mail)
 {
     if (is_null($this->_client)) {
         $this->_client = new \google\appengine\api\mail\Message();
     }
     $this->_client->addBcc($mail->getBcc());
     $this->_client->addCc($mail->getCc());
     $this->_client->addTo($mail->getTo());
     $this->_client->setHtmlBody($mail->getBodyHtml(true));
     $this->_client->setReplyTo($mail->getReplyTo());
     $this->_client->setSender($mail->getFrom());
     $this->_client->setSubject($mail->getSubject());
     $this->_client->setTextBody($mail->getBodyText(true));
     try {
         $this->_client->send();
     } catch (\Exception $exception) {
         throw new Midas_Service_AppEngine_Exception($exception);
     }
 }
Ejemplo n.º 3
0
 /**
  * Send the mail.
  *
  * @param Midas_Mail $mail mail instance
  * @throws Midas_Service_SendGrid_Exception
  */
 public function sendMail(Midas_Mail $mail)
 {
     if (is_null($this->_client)) {
         $this->_client = new \SendGrid($this->_user, $this->_key, $this->_config);
     }
     $email = new \SendGrid\Email();
     $email->setBccs($mail->getBcc());
     $email->setCcs($mail->getCc());
     $email->setHtml($mail->getBodyHtml(true));
     $email->setFrom($mail->getFrom());
     $email->setReplyTo($mail->getReplyTo());
     $email->setSubject($mail->getSubject());
     $email->setText($mail->getBodyText(true));
     $email->setTos($mail->getTo());
     try {
         $this->_client->send($email);
     } catch (\SendGrid\Exception $exception) {
         throw new Midas_Service_SendGrid_Exception('Could not send mail');
     }
 }