Exemplo n.º 1
0
 /**
  * Send mail to recipient
  *
  * @param array|string $email - E-mail(s)
  * @param null $name - receiver name(s)
  * @param array $variables - template variables
  * @return boolean
  * @throws Exception
  * @throws Zend_Mail_Exception
  */
 public function send($email, $name = null, array $variables = array())
 {
     /** @var Newsman_Newsletter_Helper_Smtp $_helper */
     $_helper = Mage::helper('newsman_newsletter/smtp');
     if (!$_helper->isEnabled()) {
         return parent::send($email, $name, $variables);
     }
     if (!$this->isValidForSend()) {
         Mage::logException(new Exception('This letter cannot be sent.'));
         // translation is intentionally omitted
         return false;
     }
     $emails = array_values((array) $email);
     $names = is_array($name) ? $name : (array) $name;
     $names = array_values($names);
     foreach ($emails as $key => $email) {
         if (!isset($names[$key])) {
             $names[$key] = substr($email, 0, strpos($email, '@'));
         }
     }
     $variables['email'] = reset($emails);
     $variables['name'] = reset($names);
     $this->setUseAbsoluteLinks(true);
     $text = $this->getProcessedTemplate($variables, true);
     $subject = $this->getProcessedTemplateSubject($variables);
     if ($this->hasQueue() && $this->getQueue() instanceof Mage_Core_Model_Email_Queue) {
         /** @var $emailQueue Mage_Core_Model_Email_Queue */
         $emailQueue = $this->getQueue();
         $emailQueue->setMessageBody($text);
         $emailQueue->setMessageParameters(array('subject' => $subject, 'is_plain' => $this->isPlain(), 'from_email' => $this->getSenderEmail(), 'from_name' => $this->getSenderName(), 'reply_to' => $this->getMail()->getReplyTo(), 'return_to' => $this->getMail()->getReturnPath()))->addRecipients($emails, $names, Mage_Core_Model_Email_Queue::EMAIL_TYPE_TO)->addRecipients($this->_bccEmails, array(), Mage_Core_Model_Email_Queue::EMAIL_TYPE_BCC);
         $emailQueue->addMessageToQueue();
         return true;
     }
     ini_set('SMTP', $_helper->getHost());
     ini_set('smtp_port', $_helper->getPort());
     $mail = $this->getMail();
     $config = array('ssl' => $_helper->getSslType(), 'port' => $_helper->getPort(), 'auth' => $_helper->getAuth(), 'username' => $_helper->getUsername(), 'password' => $_helper->getPassword());
     $mailTransport = new Zend_Mail_Transport_Smtp($_helper->getHost(), $config);
     Zend_Mail::setDefaultTransport($mailTransport);
     foreach ($emails as $key => $email) {
         $mail->addTo($email, '=?utf-8?B?' . base64_encode($names[$key]) . '?=');
     }
     if ($this->isPlain()) {
         $mail->setBodyText($text);
     } else {
         $mail->setBodyHTML($text);
     }
     $mail->setSubject('=?utf-8?B?' . base64_encode($subject) . '?=');
     $mail->setFrom($this->getSenderEmail(), $this->getSenderName());
     try {
         $mail->send();
         $this->_mail = null;
     } catch (Exception $e) {
         $this->_mail = null;
         Mage::logException($e);
         return false;
     }
     return true;
 }
Exemplo n.º 2
0
 public function testSendFailure()
 {
     $exception = new Exception('test');
     $this->_mail->expects($this->once())->method('send')->will($this->throwException($exception));
     $this->assertNull($this->_model->getSendingException());
     $this->assertFalse($this->_model->send('*****@*****.**'));
     $this->assertSame($exception, $this->_model->getSendingException());
 }
Exemplo n.º 3
0
 /**
  * Send mail to recipient
  *
  * @param   array|string       $email        E-mail(s)
  * @param   array|string|null  $name         receiver name(s)
  * @param   array              $variables    template variables
  * @return  boolean
  **/
 public function send($email, $name = null, array $variables = array())
 {
     $helper = Mage::helper('mandrill');
     //Check if should use Mandrill Transactional Email Service
     if (FALSE === $helper->useTransactionalService()) {
         return parent::send($email, $name, $variables);
     }
     if (!$this->isValidForSend()) {
         Mage::logException(new Exception('This letter cannot be sent.'));
         // translation is intentionally omitted
         return false;
     }
     $emails = array_values((array) $email);
     if (count($this->_bcc) > 0) {
         $bccEmail = $this->_bcc[0];
     } else {
         $bccEmail = '';
     }
     $names = is_array($name) ? $name : (array) $name;
     $names = array_values($names);
     foreach ($emails as $key => $email) {
         if (!isset($names[$key])) {
             $names[$key] = substr($email, 0, strpos($email, '@'));
         }
     }
     $variables['email'] = reset($emails);
     $variables['name'] = reset($names);
     $mail = $this->getMail();
     $this->setUseAbsoluteLinks(true);
     $text = $this->getProcessedTemplate($variables, true);
     try {
         $message = array('subject' => $this->getProcessedTemplateSubject($variables), 'from_name' => $this->getSenderName(), 'from_email' => $this->getSenderEmail(), 'to_email' => $emails, 'to_name' => $names, 'bcc_address' => $bccEmail, 'headers' => array('Reply-To' => $this->replyTo));
         if ($this->isPlain()) {
             $message['text'] = $text;
         } else {
             $message['html'] = $text;
         }
         $tTags = $this->_getTemplateTags();
         if (!empty($tTags)) {
             $message['tags'] = $tTags;
         }
         $sent = $mail->sendEmail($message);
         if ($mail->errorCode) {
             return false;
         }
     } catch (Exception $e) {
         Mage::logException($e);
         return false;
     }
     return true;
 }
Exemplo n.º 4
0
 public function send($email, $name = null, array $variables = array())
 {
     if (!Mage::getStoreConfig('smtp/settings/enabled')) {
         return parent::send($email, $name, $variables);
     }
     if (!$this->isValidForSend()) {
         return false;
     }
     if (is_null($name)) {
         $name = substr($email, 0, strpos($email, '@'));
     }
     $variables['email'] = $email;
     $variables['name'] = $name;
     $mail = $this->getMail();
     if (is_array($email)) {
         foreach ($email as $emailOne) {
             if (is_array($name)) {
                 $name = $name[0];
             }
             //var_dump($name);
             //die;
             $mail->addTo($emailOne, $name);
         }
     } else {
         $mail->addTo($email, $name);
     }
     $this->setUseAbsoluteLinks(true);
     $text = $this->getProcessedTemplate($variables, true);
     if ($this->isPlain()) {
         $mail->setBodyText($text);
     } else {
         $mail->setBodyHTML($text);
     }
     $mail->setSubject($this->getProcessedTemplateSubject($variables));
     $mail->setFrom($this->getSenderEmail(), $this->getSenderName());
     $transport = Mage::helper('smtp')->getTransport();
     //echo get_class($transport);
     //echo get_class($mail);
     //die;
     try {
         $mail->send($transport);
         // Zend_Mail warning..
         $this->_mail = null;
     } catch (Exception $e) {
         return false;
     }
     return true;
 }
Exemplo n.º 5
0
 /**
  * wraps send() method of parent, supplies before and after events, and
  * sends if allowed
  *
  * @param   array|string       $email        E-mail(s)
  * @param   array|string|null  $name         receiver name(s)
  * @param   array              $variables    template variables
  * @see     Mage_Core_Model_Email_Template
  * @return  boolean
  **/
 public function send($email, $name = null, array $variables = array())
 {
     if (!Mage::getStoreConfigFlag('hackathon_mailguard/settings/active')) {
         return parent::send($email, $name, $variables);
     } else {
         $return = FALSE;
         Mage::dispatchEvent('email_template_send_before', array('email' => $this, 'email_to' => $email));
         $validatedEmails = $this->getValidatedEmails();
         if (!$this->getDoNotSend() && !empty($validatedEmails)) {
             $return = parent::send($validatedEmails, $name, $variables);
             // TODO: Change the autogenerated stub
         }
         Mage::dispatchEvent('email_template_send_after', array('email' => $this, 'email_to' => $email));
         return $return;
     }
 }
Exemplo n.º 6
0
 /**
  * Send mail to recipient
  *
  * @param   array|string       $email        E-mail(s)
  * @param   array|string|null  $name         receiver name(s)
  * @param   array              $variables    template variables
  * @return  boolean
  **/
 public function send($email, $name = null, array $variables = array())
 {
     //Check if should use MC Transactional Email Service
     if (FALSE === Mage::helper('monkey')->useTransactionalService()) {
         return parent::send($email, $name, $variables);
     }
     if (!$this->isValidForSend()) {
         Mage::logException(new Exception('This letter cannot be sent.'));
         // translation is intentionally omitted
         return false;
     }
     $emails = array_values((array) $email);
     $names = is_array($name) ? $name : (array) $name;
     $names = array_values($names);
     foreach ($emails as $key => $email) {
         if (!isset($names[$key])) {
             $names[$key] = substr($email, 0, strpos($email, '@'));
         }
     }
     $variables['email'] = reset($emails);
     $variables['name'] = reset($names);
     ini_set('SMTP', Mage::getStoreConfig('system/smtp/host'));
     ini_set('smtp_port', Mage::getStoreConfig('system/smtp/port'));
     $service = Mage::helper('monkey')->config('transactional_emails');
     $apiKey = Mage::helper('monkey')->getApiKey($this->getDesignConfig()->getStore());
     if ('mandrill' == $service) {
         $apiKey = Mage::helper('monkey')->getMandrillApiKey($this->getDesignConfig()->getStore());
     }
     $mail = Ebizmarts_MageMonkey_Model_TransactionalEmail_Adapter::factory($service);
     $mail->setApiKey($apiKey);
     $this->setUseAbsoluteLinks(true);
     $text = $this->getProcessedTemplate($variables, true);
     try {
         $message = array('html' => $text, 'text' => $text, 'subject' => '=?utf-8?B?' . base64_encode($this->getProcessedTemplateSubject($variables)) . '?=', 'from_name' => $this->getSenderName(), 'from_email' => $this->getSenderEmail(), 'to_email' => $emails, 'to_name' => $names);
         $sent = $mail->sendEmail($message);
         if ($mail->errorCode) {
             return false;
         }
     } catch (Exception $e) {
         Mage::logException($e);
         return false;
     }
     return true;
 }
Exemplo n.º 7
0
 /**
  * @param array|string $email
  * @param null $name
  * @param array $variables
  * @return bool
  */
 public function send($email, $name = null, array $variables = array())
 {
     $storeId = Mage::app()->getStore()->getId();
     if (!Mage::getStoreConfig(Ebizmarts_Mandrill_Model_System_Config::ENABLE, $storeId)) {
         return parent::send($email, $name, $variables);
     }
     if (!$this->isValidForSend()) {
         Mage::logException(new Exception('This letter cannot be sent.'));
         // translation is intentionally omitted
         return false;
     }
     $emails = array_values((array) $email);
     $names = is_array($name) ? $name : (array) $name;
     $names = array_values($names);
     foreach ($emails as $key => $email) {
         if (!isset($names[$key])) {
             $names[$key] = substr($email, 0, strpos($email, '@'));
         }
     }
     // Get message
     $this->setUseAbsoluteLinks(true);
     $variables['email'] = reset($emails);
     $variables['name'] = reset($names);
     $message = $this->getProcessedTemplate($variables, true);
     $email = array('subject' => $this->getProcessedTemplateSubject($variables), 'to' => array());
     $mail = $this->getMail();
     $max = count($emails);
     for ($i = 0; $i < $max; $i++) {
         if (isset($names[$i])) {
             $email['to'][] = array('email' => $emails[$i], 'name' => $names[$i]);
         } else {
             $email['to'][] = array('email' => $emails[$i], 'name' => '');
         }
     }
     foreach ($mail->getBcc() as $bcc) {
         $email['to'][] = array('email' => $bcc, 'type' => 'bcc');
     }
     $email['from_name'] = $this->getSenderName();
     $email['from_email'] = $this->getSenderEmail();
     $headers = $mail->getHeaders();
     $headers[] = Mage::helper('ebizmarts_mandrill')->getUserAgent();
     $email['headers'] = $headers;
     if (isset($variables['tags']) && count($variables['tags'])) {
         $email['tags'] = $variables['tags'];
     }
     if (isset($variables['tags']) && count($variables['tags'])) {
         $email['tags'] = $variables['tags'];
     } else {
         $templateId = (string) $this->getId();
         $templates = parent::getDefaultTemplates();
         if (isset($templates[$templateId]) && isset($templates[$templateId]['label'])) {
             $email['tags'] = array(substr($templates[$templateId]['label'], 0, 50));
         } else {
             if ($this->getTemplateCode()) {
                 $email['tags'] = array(substr($this->getTemplateCode(), 0, 50));
             } else {
                 if ($templateId) {
                     $email['tags'] = array(substr($templateId, 0, 50));
                 } else {
                     $email['tags'] = array('default_tag');
                 }
             }
         }
     }
     if ($att = $mail->getAttachments()) {
         $email['attachments'] = $att;
     }
     if ($this->isPlain()) {
         $email['text'] = $message;
     } else {
         $email['html'] = $message;
     }
     try {
         $result = $mail->messages->send($email);
     } catch (Exception $e) {
         Mage::logException($e);
         return false;
     }
     return true;
 }
 /**
  * Send mail to recipient
  *
  * @see Mage_Core_Model_Email_Template::send()
  * @param   array|string       $email        E-mail(s)
  * @param   array|string|null  $name         receiver name(s)
  * @param   array              $variables    template variables
  * @param   int                $sendType
  * @return  boolean
  **/
 public function send($email, $name = null, array $variables = array(), $sendType = null)
 {
     //not mapped templates or mapped as "Use system default"
     if ($sendType == null) {
         return parent::send($email, $name, $variables);
     }
     $transEnabled = Mage::getStoreConfig(Dotdigitalgroup_Email_Helper_Transactional::XML_PATH_TRANSACTIONAL_API_ENABLED);
     //mapped option "Send via connector"
     if ($sendType == 1 && $transEnabled) {
         return $this->sendViaConnector($email, $name, $variables);
     }
 }
Exemplo n.º 9
0
 /**
  * Send mail to recipient
  *
  * @param array|string      $email     E-mail(s)
  * @param array|string|null $name      receiver name(s)
  * @param array             $variables template variables
  *
  * @return boolean
  */
 public function send($email, $name = null, array $variables = array())
 {
     // In the rare case we got here w/o hitting sendTransactional first...
     if (!isset($variables['store']) || !is_object($variables['store'])) {
         // Get the current store view, as to not break things
         $variables['store'] = Mage::app()->getStore();
     }
     // If not set to go through Bronto, fall through to magento sending
     if (!Mage::helper($this->_helper)->canSendBronto($this, $variables['store']->getId())) {
         return parent::send($email, $name, $variables);
     }
     $messageId = $this->getBrontoMessageId();
     $sendType = $this->getTemplateSendType();
     if ($sendType != 'transactional') {
         $sendType = 'triggered';
     }
     // If messageId is empty, send through Magento
     if (empty($messageId)) {
         return parent::send($email, $name, $variables);
     }
     // If message is not valid for sending, return false
     if (!$this->isMessageValidForSend()) {
         return false;
     }
     // Handle CC and BCC by simply adding as array
     $emails = array_values((array) $email);
     $names = is_array($name) ? $name : (array) $name;
     $names = array_values($names);
     foreach ($emails as $key => $email) {
         if (!isset($names[$key])) {
             $names[$key] = substr($email, 0, strpos($email, '@'));
         }
     }
     $variables['email'] = reset($emails);
     $variables['name'] = reset($names);
     $this->setUseAbsoluteLinks(true);
     $delivery = new Bronto_Api_Model_Delivery();
     $delivery = $this->getProcessedDelivery($delivery, $variables);
     $this->_additionalFields($delivery, $variables);
     $productContext = Mage::helper('bronto_product')->itemsToProductHash($this->getTemplateFilter()->getProductContext(), $variables['store']->getId());
     $sendOptions = Mage::getModel('bronto_common/system_config_source_sendOptions');
     $sendOption = $this->_getSendFlags($variables['store']->getId());
     if ($sendOptions->setDeliveryFlags($delivery, $sendOption)) {
         $optionLabels = $sendOptions->toArray();
         Mage::helper($this->_helper)->writeDebug("Setting send flags for messageId {$this->getBrontoMessageId()}: {$optionLabels[$sendOption]}");
     }
     $data = array('emails' => $emails, 'params' => $this->_additionalData(), 'recommendation' => array('product_ids' => array_keys($productContext), 'customer' => $this->getTemplateFilter()->getCustomerId(), 'id' => $this->_getRecommendationId($variables['store']->getId())), 'delivery' => array('messageId' => $messageId, 'type' => $sendType ? $sendType : 'transactional', 'fromEmail' => $this->getSenderEmail(), 'fromName' => $this->getSenderName(), 'replyEmail' => $this->getSenderEmail()) + $delivery->toArray());
     $queue = Mage::getModel('bronto_common/queue')->setStoreId($variables['store']->getId())->setUnserializedEmailData($data)->setEmailClass($this->_emailClass())->setCreatedAt(Mage::getSingleton('core/date')->gmtDate());
     $apiHelper = Mage::helper('bronto_common/api');
     if ($this->_queuable() && $apiHelper->canUseQueue('store', $queue->getStoreId())) {
         try {
             $queue->save();
             return true;
         } catch (Exception $e) {
             $apiHelper->writeError('Failed to save email to queue for store ' . $queue->getStoreId() . ': ' . $e->getMessage());
             return $this->sendDeliveryFromQueue($queue);
         }
     } else {
         $api = $apiHelper->getApi(null, 'store', $variables['store']->getId());
         return $this->sendDeliveryFromQueue($queue->setApi($api));
     }
 }
Exemplo n.º 10
0
 public function send($email, $name = null, array $variables = array())
 {
     if (!Mage::helper('mailchimp')->isStsActivated()) {
         return parent::send($email, $name, $variables);
     }
     if (!$this->isValidForSend()) {
         Mage::logException(new Exception('This letter cannot be sent.'));
         // translation is intentionally omitted
         return false;
     }
     if (is_null($name)) {
         $name = substr($email, 0, strpos($email, '@'));
     }
     $variables['email'] = $email;
     $variables['name'] = $name;
     ini_set('SMTP', Mage::getStoreConfig('system/smtp/host'));
     ini_set('smtp_port', Mage::getStoreConfig('system/smtp/port'));
     $setReturnPath = Mage::getStoreConfig(self::XML_PATH_SENDING_SET_RETURN_PATH);
     switch ($setReturnPath) {
         case 1:
             $returnPathEmail = $this->getSenderEmail();
             break;
         case 2:
             $returnPathEmail = Mage::getStoreConfig(self::XML_PATH_SENDING_RETURN_PATH_EMAIL);
             break;
         default:
             $returnPathEmail = null;
             break;
     }
     $this->setUseAbsoluteLinks(true);
     $text = $this->getProcessedTemplate($variables, true);
     $to_names = array();
     array_push($to_names, $name);
     $to_emails = array();
     if (is_array($email)) {
         foreach ($email as $emailOne) {
             array_push($to_emails, $emailOne);
         }
     } else {
         array_push($to_emails, $email);
     }
     $apikey = Mage::helper('mailchimp')->getApiKey();
     $url = "http://" . substr($apikey, -3) . ".sts.mailchimp.com/1.0/SendEmail";
     $message = array('html' => $text, 'text' => $text, 'subject' => '=?utf-8?B?' . base64_encode($this->getProcessedTemplateSubject($variables)) . '?=', 'from_name' => $this->getSenderName(), 'from_email' => $this->getSenderEmail(), 'to_email' => $to_emails, 'to_name' => $to_names);
     $params = array('apikey' => $apikey, 'message' => $message, 'track_opens' => true, 'track_clicks' => false, 'tags' => '');
     $ch = curl_init();
     /*****this code has been updated thanks to manisanjai*****************************/
     curl_setopt($ch, CURLOPT_URL, $url);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     curl_setopt($ch, CURLOPT_POST, true);
     curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($params));
     /*****this code has been updated thanks to manisanjai*****************************/
     $result = curl_exec($ch);
     curl_close($ch);
     $data = json_decode($result);
     if (isset($data->message_id)) {
         Mage::getSingleton('adminhtml/session')->addSuccess('e-mail successfully sent.');
     } else {
         Mage::getSingleton('adminhtml/session')->addError('There was an error sending your email, internal code error: ' . $data->aws_code);
         return false;
     }
     return true;
 }
Exemplo n.º 11
0
 /**
  * Send mail to recipient
  *
  * @param array|string      $email     E-mail(s)
  * @param array|string|null $name      receiver name(s)
  * @param array             $variables template variables
  *
  * @return boolean
  */
 public function send($email, $name = null, array $variables = array())
 {
     // If not set to go through Bronto, fall through to magento sending
     if (!Mage::helper($this->_helper)->canSendBronto($this, $variables['store']->getId())) {
         return parent::send($email, $name, $variables);
     }
     /* @var $message Bronto_Api_Message_Row */
     $message = $this->getMessage();
     $messageId = $this->getBrontoMessageId();
     // If messageId is empty, send through Magento
     if (empty($messageId)) {
         return parent::send($email, $name, $variables);
     }
     // If message is not valid for sending, return false
     if (!$this->isMessageValidForSend()) {
         return false;
     }
     // Handle CC and BCC by simply adding as array
     $emails = array_values((array) $email);
     $names = is_array($name) ? $name : (array) $name;
     $names = array_values($names);
     foreach ($emails as $key => $email) {
         if (!isset($names[$key])) {
             $names[$key] = substr($email, 0, strpos($email, '@'));
         }
     }
     $variables['email'] = reset($emails);
     $variables['name'] = reset($names);
     // Load Bronto Contact(s)
     $contacts = array();
     foreach ($emails as $key => $email) {
         Mage::helper('bronto_common/contact')->writeDebug('  Getting Contact Object for: ' . $email . ' - Store: ' . $variables['store']->getId());
         $contacts[$key] = Mage::helper('bronto_common/contact')->getContactByEmail($email, $this->_helper, $variables['store']->getId(), 2);
     }
     $deliveryCount = 0;
     $deliveryErrors = 0;
     /* @var $contact Bronto_Api_Contact_Row */
     foreach ($contacts as $contact) {
         try {
             // If contact does not have id, create contact, if still no id, log it
             if (!$contact->id || empty($contact->id)) {
                 $contact = Mage::helper('bronto_common/contact')->saveContact($contact);
                 if (!$contact->id || empty($contact->id)) {
                     $this->_beforeSend($contact, $message);
                     $deliveryErrors++;
                     Mage::helper($this->_helper)->writeDebug('  TEST MODE: Skipping e-mail: ' . $contact->email);
                     $this->_afterSend(0, "TEST MODE ENABLED: Contact does not exist: " . $contact->email);
                     continue;
                 }
             }
             // Trigger _beforeSend action for logging
             $this->_beforeSend($contact, $message);
             /* @var $deliveryObject Bronto_Api_Delivery */
             Mage::helper($this->_helper)->writeDebug('  Getting Delivery Object...');
             $client = Mage::helper($this->_helper)->getApi(null, 'store', $variables['store']->getId());
             $deliveryObject = Mage::getModel('bronto_common/delivery', array('api' => $client, 'email_class' => $this->_emailClass()));
             $deliveryCount++;
             Mage::helper($this->_helper)->writeDebug('    Delivery Object Created Successfully');
             Mage::helper($this->_helper)->writeDebug('  Creating Delivery Row...');
             /* @var $delivery Bronto_Api_Delivery_Row */
             $delivery = $deliveryObject->createRow();
             $delivery->start = Mage::getModel('core/date')->date('c');
             $delivery->messageId = $message->id;
             $delivery->type = $this->getTemplateSendType() ? $this->getTemplateSendType() : 'transactional';
             $delivery->fromEmail = $this->getSenderEmail();
             $delivery->fromName = $this->getSenderName();
             $delivery->replyEmail = $this->getSenderEmail();
             $recipients = array(array('type' => 'contact', 'id' => $contact->id, 'deliveryType' => 'selected'));
             foreach (Mage::getModel('bronto_common/list', $this->_helper)->addAdditionalRecipients($variables['store']->getId()) as $exclude) {
                 $recipients[] = $exclude;
             }
             $delivery->recipients = $recipients;
             Mage::helper($this->_helper)->writeDebug('  Processing Delivery');
             $delivery = $this->getProcessedDelivery($delivery, $variables);
             Mage::helper($this->_helper)->writeDebug('  Saving Delivery...');
             $delivery->save();
             if ($delivery->id) {
                 $this->setLastDeliveryId($delivery->id);
                 $this->_afterSend(true, null, $delivery);
             } else {
                 $deliveryErrors++;
                 $this->_afterSend(false, null, $delivery);
             }
         } catch (Exception $e) {
             $errorMessage = $e->getMessage();
             if ($e->getCode() === Bronto_Api_Delivery_Exception::MESSAGE_NOT_TRANSACTIONAL_APPROVED) {
                 // Replace message id with message name
                 if (preg_match_all("/([a-zA-Z0-9\\-]){36}/", $errorMessage, $matches)) {
                     // Grab field id if exists
                     foreach ($matches[0] as $match) {
                         $errorMessage = str_replace($match, $message->name, $errorMessage);
                     }
                 }
             }
             $deliveryErrors++;
             Mage::helper($this->_helper)->writeError($errorMessage);
             $this->_afterSend(false, $errorMessage, isset($delivery) ? $delivery : null);
         }
     }
     return $deliveryErrors == 0;
 }
Exemplo n.º 12
0
 public function send($email, $name = null, array $variables = array())
 {
     // If it's not enabled, just return the parent result.
     if (!Mage::helper('smtppro')->isEnabled()) {
         return parent::send($email, $name, $variables);
     }
     Mage::log('SMTPPro is enabled, sending email in Aschroder_SMTPPro_Model_Email_Template');
     // The remainder of this function closely mirrors the parent
     // method except for providing the SMTP auth details from the
     // configuration. This is not good OO, but the parent class
     // leaves little room for useful subclassing. This will probably
     // become redundant sooner or later anyway.
     if (!$this->isValidForSend()) {
         Mage::log('SMTPPro: Email not valid for sending - check template, and smtp enabled/disabled setting');
         Mage::logException(new Exception('This letter cannot be sent.'));
         // translation is intentionally omitted
         return false;
     }
     $emails = array_values((array) $email);
     $names = is_array($name) ? $name : (array) $name;
     $names = array_values($names);
     foreach ($emails as $key => $email) {
         if (!isset($names[$key])) {
             $names[$key] = substr($email, 0, strpos($email, '@'));
         }
     }
     $variables['email'] = reset($emails);
     $variables['name'] = reset($names);
     $mail = $this->getMail();
     $dev = Mage::helper('smtppro')->getDevelopmentMode();
     if ($dev == "contact") {
         $email = Mage::getStoreConfig('contacts/email/recipient_email', $this->getDesignConfig()->getStore());
         Mage::log("Development mode set to send all emails to contact form recipient: " . $email);
     } elseif ($dev == "supress") {
         Mage::log("Development mode set to supress all emails.");
         # we bail out, but report success
         return true;
     }
     // In Magento core they set the Return-Path here, for the sendmail command.
     // we assume our outbound SMTP server (or Gmail) will set that.
     foreach ($emails as $key => $email) {
         $mail->addTo($email, '=?utf-8?B?' . base64_encode($names[$key]) . '?=');
     }
     $this->setUseAbsoluteLinks(true);
     $text = $this->getProcessedTemplate($variables, true);
     if ($this->isPlain()) {
         $mail->setBodyText($text);
     } else {
         $mail->setBodyHTML($text);
     }
     $mail->setSubject('=?utf-8?B?' . base64_encode($this->getProcessedTemplateSubject($variables)) . '?=');
     $mail->setFrom($this->getSenderEmail(), $this->getSenderName());
     // If we are using store emails as reply-to's set the header
     // Check the header is not already set by the application.
     // The contact form, for example, set's it to the sender of
     // the contact. Thanks i960 for pointing this out.
     if (Mage::helper('smtppro')->isReplyToStoreEmail() && !array_key_exists('Reply-To', $mail->getHeaders())) {
         // Patch for Zend upgrade
         // Later versions of Zend have a method for this, and disallow direct header setting...
         if (method_exists($mail, "setReplyTo")) {
             $mail->setReplyTo($this->getSenderEmail(), $this->getSenderName());
         } else {
             $mail->addHeader('Reply-To', $this->getSenderEmail());
         }
         Mage::log('ReplyToStoreEmail is enabled, just set Reply-To header: ' . $this->getSenderEmail());
     }
     $transport = Mage::helper('smtppro')->getTransport($this->getDesignConfig()->getStore());
     try {
         Mage::log('About to send email');
         $mail->send($transport);
         // Zend_Mail warning..
         Mage::log('Finished sending email');
         // Record one email for each receipient
         foreach ($emails as $key => $email) {
             Mage::dispatchEvent('smtppro_email_after_send', array('to' => $email, 'template' => $this->getTemplateId(), 'subject' => $this->getProcessedTemplateSubject($variables), 'html' => !$this->isPlain(), 'email_body' => $text));
         }
         $this->_mail = null;
     } catch (Exception $e) {
         Mage::logException($e);
         return false;
     }
     return true;
 }
Exemplo n.º 13
0
 public function send($email, $name = null, array $variables = array())
 {
     //Get appropriate store
     if (isset($variables['store'])) {
         $store = $variables['store'];
     } elseif ($this->getDesignConfig()->getStore()) {
         $store = Mage::getModel('core/store')->load($this->getDesignConfig()->getStore());
     } else {
         $store = Mage::app()->getStore();
     }
     if ($store->getConfig('mailgun/general/active')) {
         if (!$this->isValidForSend()) {
             Mage::logException(new Exception('This letter cannot be sent.'));
             return false;
         }
         $message = Mage::getModel('freelunchlabs_mailgun/messagebuilder');
         //Recipient(s)
         $emails = array_values((array) $email);
         $names = is_array($name) ? $name : (array) $name;
         $names = array_values($names);
         foreach ($emails as $key => $email) {
             if (!isset($names[$key])) {
                 $names[$key] = substr($email, 0, strpos($email, '@'));
             }
         }
         $variables['email'] = reset($emails);
         $variables['name'] = reset($names);
         //Add To Recipients
         $isPrimary = true;
         foreach ($emails as $key => $email) {
             if ($isPrimary) {
                 //Add primary recipient
                 $message->setPrimaryRecipient($email);
             }
             $isPrimary = false;
             $message->addToRecipient($names[$key] . " <" . $email . ">");
         }
         //Subject
         $subject = $this->getProcessedTemplateSubject($variables);
         $message->setSubject($subject);
         //From Name
         $message->setFromAddress($this->getSenderName() . " <" . $this->getSenderEmail() . ">");
         //Bcc
         if (is_array($this->bcc)) {
             foreach ($this->bcc as $bcc_email) {
                 $message->addBccRecipient($bcc_email);
             }
         } elseif ($this->bcc) {
             $message->addBccRecipient($this->bcc);
         }
         //Reply To
         if (!is_null($this->replyto)) {
             $message->setReplyToAddress($this->replyto);
         }
         //Message Body
         $this->setUseAbsoluteLinks(true);
         $processedTemplateBody = $this->getProcessedTemplate($variables, true);
         if ($this->isPlain()) {
             $message->setTextBody($processedTemplateBody);
         } else {
             $message->setHtmlBody($processedTemplateBody);
         }
         //Add Unique Args
         $message->addCustomData("message_data", array('id' => 123456));
         //Tag message with type
         $message->addTag($this->getTemplateId());
         $message->addTag($store->getConfig('mailgun/general/tag'));
         if ($store->getConfig('mailgun/events/opens')) {
             $message->setOpenTracking(true);
         }
         if ($store->getConfig('mailgun/events/clicks')) {
             $message->setClickTracking(true);
         }
         //Set store
         $message->setStore($store);
         //Send it!
         try {
             Mage::getModel('freelunchlabs_mailgun/mailgun')->send($message);
             $this->_mail = null;
         } catch (Exception $e) {
             $this->_mail = null;
             Mage::logException($e);
             return false;
         }
         return true;
     } else {
         return parent::send($email, $name, $variables);
     }
 }
Exemplo n.º 14
0
 public function send($email, $name = null, array $variables = array())
 {
     if ($this->_isFake) {
         $registryContentKey = $this->_registryContentKey;
         if (Mage::registry($registryContentKey)) {
             Mage::unregister($registryContentKey);
         }
         $registrySubjectKey = $this->_registrySubjectKey;
         if (Mage::registry($registrySubjectKey)) {
             Mage::unregister($registrySubjectKey);
         }
         $emails = array_values((array) $email);
         $names = is_array($name) ? $name : (array) $name;
         $names = array_values($names);
         foreach ($emails as $key => $email) {
             if (!isset($names[$key])) {
                 $names[$key] = substr($email, 0, strpos($email, '@'));
             }
         }
         $variables['email'] = reset($emails);
         $variables['name'] = reset($names);
         $this->setUseAbsoluteLinks(true);
         $content = $this->getProcessedTemplate($variables);
         $subject = $this->getProcessedTemplateSubject($variables);
         Mage::register($registryContentKey, $content, true);
         Mage::register($registrySubjectKey, $subject, true);
         return true;
     } else {
         return parent::send($email, $name, $variables);
     }
 }
 /**
  * Send mail to recipient
  *
  * @param   array|string       $email        E-mail(s)
  * @param   array|string|null  $name         receiver name(s)
  * @param   array              $variables    template variables
  * @return  boolean
  **/
 public function send($email, $name = null, array $variables = array())
 {
     $_helper = Mage::helper('smtppro');
     // If it's not enabled, just return the parent result.
     if (!$_helper->isEnabled()) {
         $_helper->log('SMTP Pro is not enabled, fall back to parent class');
         return parent::send($email, $name, $variables);
     }
     // As per parent class - except addition of before and after send events
     if (!$this->isValidForSend()) {
         $_helper->log('Email is not valid for sending, this is a core error that often means there\'s a problem with your email templates.');
         Mage::logException(new Exception('This letter cannot be sent.'));
         // translation is intentionally omitted
         return false;
     }
     $emails = array_values((array) $email);
     $names = is_array($name) ? $name : (array) $name;
     $names = array_values($names);
     foreach ($emails as $key => $email) {
         if (!isset($names[$key])) {
             $names[$key] = substr($email, 0, strpos($email, '@'));
         }
     }
     $variables['email'] = reset($emails);
     $variables['name'] = reset($names);
     $this->setUseAbsoluteLinks(true);
     $text = $this->getProcessedTemplate($variables, true);
     $subject = $this->getProcessedTemplateSubject($variables);
     $setReturnPath = Mage::getStoreConfig(self::XML_PATH_SENDING_SET_RETURN_PATH);
     switch ($setReturnPath) {
         case 1:
             $returnPathEmail = $this->getSenderEmail();
             break;
         case 2:
             $returnPathEmail = Mage::getStoreConfig(self::XML_PATH_SENDING_RETURN_PATH_EMAIL);
             break;
         default:
             $returnPathEmail = null;
             break;
     }
     // Use the queue IFF it's not bypassed and it's been set.
     if (!$_helper->isQueueBypassed() && $this->hasQueue() && $this->getQueue() instanceof Mage_Core_Model_Email_Queue) {
         /** @var $emailQueue Mage_Core_Model_Email_Queue */
         $emailQueue = $this->getQueue();
         $emailQueue->setMessageBody($text);
         $emailQueue->setMessageParameters(array('subject' => $subject, 'return_path_email' => $returnPathEmail, 'is_plain' => $this->isPlain(), 'from_email' => $this->getSenderEmail(), 'from_name' => $this->getSenderName(), 'reply_to' => $this->getMail()->getReplyTo(), 'return_to' => $this->getMail()->getReturnPath()))->addRecipients($emails, $names, Mage_Core_Model_Email_Queue::EMAIL_TYPE_TO)->addRecipients($this->_bccEmails, array(), Mage_Core_Model_Email_Queue::EMAIL_TYPE_BCC);
         $emailQueue->addMessageToQueue();
         $_helper->log('Email not sent immediately, queued for sending.');
         return true;
     }
     ini_set('SMTP', Mage::getStoreConfig('system/smtp/host'));
     ini_set('smtp_port', Mage::getStoreConfig('system/smtp/port'));
     $mail = $this->getMail();
     if ($returnPathEmail !== null) {
         $mailTransport = new Zend_Mail_Transport_Sendmail("-f" . $returnPathEmail);
         Zend_Mail::setDefaultTransport($mailTransport);
     }
     foreach ($emails as $key => $email) {
         $mail->addTo($email, '=?utf-8?B?' . base64_encode($names[$key]) . '?=');
     }
     if ($this->isPlain()) {
         $mail->setBodyText($text);
     } else {
         $mail->setBodyHTML($text);
     }
     $mail->setSubject('=?utf-8?B?' . base64_encode($subject) . '?=');
     $mail->setFrom($this->getSenderEmail(), $this->getSenderName());
     foreach (Mage::app()->getStores() as $store) {
         if ($this->getSenderEmail() == Mage::getStoreConfig('trans_email/ident_sales/email', $store->getStoreId())) {
             $storeid = $store->getStoreId();
         }
     }
     try {
         $transport = new Varien_Object();
         Mage::dispatchEvent('aschroder_smtppro_template_before_send', array('mail' => $mail, 'template' => $this, 'variables' => $variables, 'transport' => $transport, 'store_id' => isset($storeid) ? $storeid : null));
         if ($transport->getTransport()) {
             // if set by an observer, use it
             $mail->send($transport->getTransport());
         } else {
             $mail->send();
         }
         foreach ($emails as $key => $email) {
             Mage::dispatchEvent('aschroder_smtppro_after_send', array('to' => $email, 'template' => $this->getTemplateId(), 'subject' => $subject, 'html' => !$this->isPlain(), 'email_body' => $text));
         }
         $this->_mail = null;
     } catch (Exception $e) {
         $this->_mail = null;
         Mage::logException($e);
         return false;
     }
     return true;
 }
 /**
  * Send mail to recipient
  *
  * @param   array|string       $email        E-mail(s)
  * @param   array|string|null  $name         receiver name(s)
  * @param   array              $variables    template variables
  * @return  boolean
  **/
 public function send($email, $name = null, array $variables = array())
 {
     /**
      * Return default parent method if Sailthru Extension
      * or Transactional Email has not been enabled
      */
     if (!Mage::helper('sailthruemail')->isEnabled() || !Mage::helper('sailthruemail')->isTransactionalEmailEnabled()) {
         return parent::send($email, $name, $variables);
     }
     if (!$this->isValidForSend()) {
         Mage::logException(new Exception('This letter cannot be sent.'));
         // translation is intentionally omitted
         return false;
     }
     $emails = array_values((array) $email);
     $names = is_array($name) ? $name : (array) $name;
     $names = array_values($names);
     foreach ($emails as $key => $email) {
         if (!isset($names[$key])) {
             $names[$key] = substr($email, 0, strpos($email, '@'));
         }
     }
     $variables['email'] = reset($emails);
     $variables['name'] = reset($names);
     ini_set('SMTP', Mage::getStoreConfig('system/smtp/host'));
     ini_set('smtp_port', Mage::getStoreConfig('system/smtp/port'));
     $mail = $this->getMail();
     $setReturnPath = Mage::getStoreConfig(self::XML_PATH_SENDING_SET_RETURN_PATH);
     switch ($setReturnPath) {
         case 1:
             $returnPathEmail = $this->getSenderEmail();
             break;
         case 2:
             $returnPathEmail = Mage::getStoreConfig(self::XML_PATH_SENDING_RETURN_PATH_EMAIL);
             break;
         default:
             $returnPathEmail = null;
             break;
     }
     if ($returnPathEmail !== null) {
         $mailTransport = new Zend_Mail_Transport_Sendmail("-f" . $returnPathEmail);
         Zend_Mail::setDefaultTransport($mailTransport);
     }
     foreach ($emails as $key => $email) {
         $mail->addTo($email, '=?utf-8?B?' . base64_encode($names[$key]) . '?=');
     }
     $this->setUseAbsoluteLinks(true);
     $text = $this->getProcessedTemplate($variables, true);
     if ($this->isPlain()) {
         $mail->setBodyText($text);
     } else {
         $mail->setBodyHTML($text);
     }
     //Prevent Zend_Mail "Subject Set Twice" Error
     $mail_subject = '=?utf-8?B?' . base64_encode($this->getProcessedTemplateSubject($variables)) . '?=';
     $mail->clearSubject();
     $mail->setSubject($mail_subject);
     //Prevent Zend_Mail "From Set Twice" Error
     $mail_from_email = $this->getSenderEmail();
     $mail_from_name = $this->getSenderName();
     $mail->clearFrom();
     $mail->setFrom($mail_from_email, $mail_from_name);
     //sailthru//
     try {
         if ($this->getData('template_code')) {
             $template_name = $this->getData('template_code');
         } else {
             $template_name = $this->getId();
         }
         $options = array('behalf_email' => $this->getSenderEmail());
         $email = $emails;
         $vars = null;
         $evars = array();
         for ($i = 0; $i < count($emails); $i++) {
             $evars[$emails[$i]] = array("content" => $text, "subj" => $this->getProcessedTemplateSubject($variables));
         }
         $client = Mage::getModel('sailthruemail/client');
         $response = $client->multisend($template_name, $emails, $vars, $evars, $options);
         if (isset($response["error"]) && $response['error'] == 14) {
             //Create template if it does not already exist
             $tempvars = array("content_html" => "{content} {beacon}", "subject" => "{subj}");
             $tempsuccess = $client->saveTemplate($template_name, $tempvars);
             $response = $client->multisend($template_name, $emails, $vars, $evars, $options);
             if ($response["error"]) {
                 Mage::throwException($this->__($response["errormsg"]));
             }
         }
     } catch (Exception $e) {
         $this->_mail = null;
         Mage::logException($e);
         return false;
     }
     return true;
 }
Exemplo n.º 17
0
 public function send($email, $name = null, array $variables = array())
 {
     $this->getSentEmailModel()->addSender($this->getSenderEmail(), $this->getSenderName());
     $this->getSentEmailModel()->setTemplateId($this->getId());
     if (isset($variables['store'])) {
         $store = $variables['store'];
     } else {
         $store = Mage::app()->getStore();
     }
     $this->getMail($store->getId());
     $this->getSentEmailModel()->setStoreId($store->getId());
     /* set return path to false, to avoid changing transport type by send method in parent class */
     /* we check this configuration in _getReturnPath method, and we set return path before */
     Mage::app()->getStore()->setConfig(Mage_Core_Model_Email_Template::XML_PATH_SENDING_SET_RETURN_PATH, false);
     try {
         $result = parent::send($email, $name, $variables);
         $this->_saveSentEmail($email, $name, $result);
     } catch (Exception $e) {
         $this->getSentEmailModel()->setComment($e->getMessage());
         $this->_saveSentEmail($email, $name, false);
         Mage::throwException($e->getMessage());
     }
     return $result;
 }
Exemplo n.º 18
0
 /**
  * Send mail to recipient
  *
  * @param   array|string       $email        E-mail(s)
  * @param   array|string|null  $name         receiver name(s)
  * @param   array              $variables    template variables
  * @return  boolean
  **/
 public function send($email, $name = null, array $variables = array())
 {
     $_helper = Mage::helper('smtppro');
     // If it's not enabled, just return the parent result.
     if (!$_helper->isEnabled()) {
         $_helper->log('SMTP Pro is not enabled, fall back to parent class');
         return parent::send($email, $name, $variables);
     }
     // As per parent class - except addition of before and after send events
     if (!$this->isValidForSend()) {
         $_helper->log('Email is not valid for sending, this is a core error that often means there\'s a problem with your email templates.');
         Mage::logException(new Exception('This letter cannot be sent.'));
         // translation is intentionally omitted
         return false;
     }
     $emails = array_values((array) $email);
     $names = is_array($name) ? $name : (array) $name;
     $names = array_values($names);
     foreach ($emails as $key => $email) {
         if (!isset($names[$key])) {
             $names[$key] = substr($email, 0, strpos($email, '@'));
         }
     }
     $variables['email'] = reset($emails);
     $variables['name'] = reset($names);
     ini_set('SMTP', Mage::getStoreConfig('system/smtp/host'));
     ini_set('smtp_port', Mage::getStoreConfig('system/smtp/port'));
     $mail = $this->getMail();
     $setReturnPath = Mage::getStoreConfig(self::XML_PATH_SENDING_SET_RETURN_PATH);
     switch ($setReturnPath) {
         case 1:
             $returnPathEmail = $this->getSenderEmail();
             break;
         case 2:
             $returnPathEmail = Mage::getStoreConfig(self::XML_PATH_SENDING_RETURN_PATH_EMAIL);
             break;
         default:
             $returnPathEmail = null;
             break;
     }
     if ($returnPathEmail !== null) {
         $mailTransport = new Zend_Mail_Transport_Sendmail("-f" . $returnPathEmail);
         Zend_Mail::setDefaultTransport($mailTransport);
     }
     foreach ($emails as $key => $email) {
         $mail->addTo($email, '=?utf-8?B?' . base64_encode($names[$key]) . '?=');
     }
     $this->setUseAbsoluteLinks(true);
     $text = $this->getProcessedTemplate($variables, true);
     if ($this->isPlain()) {
         $mail->setBodyText($text);
     } else {
         $mail->setBodyHTML($text);
     }
     $mail->setSubject('=?utf-8?B?' . base64_encode($this->getProcessedTemplateSubject($variables)) . '?=');
     $mail->setFrom($this->getSenderEmail(), $this->getSenderName());
     try {
         $transport = new Varien_Object();
         Mage::dispatchEvent('aschroder_smtppro_template_before_send', array('mail' => $mail, 'template' => $this, 'variables' => $variables, 'transport' => $transport));
         if ($transport->getTransport()) {
             // if set by an observer, use it
             $mail->send($transport->getTransport());
         } else {
             $mail->send();
         }
         foreach ($emails as $key => $email) {
             Mage::dispatchEvent('aschroder_smtppro_after_send', array('to' => $email, 'template' => $this->getTemplateId(), 'subject' => $this->getProcessedTemplateSubject($variables), 'html' => !$this->isPlain(), 'email_body' => $text));
         }
         $this->_mail = null;
     } catch (Exception $e) {
         $this->_mail = null;
         Mage::logException($e);
         return false;
     }
     return true;
 }