/**
  * @group ZF-8988
  */
 public function testReturnPathIsUsedAsMailFrom()
 {
     $connectionMock = $this->getMock('Zend_Mail_Protocol_Smtp');
     $connectionMock->expects($this->once())->method('mail')->with('*****@*****.**');
     $transport = new Zend_Mail_Transport_Smtp($this->_params['host'], $this->_params);
     $transport->setConnection($connectionMock);
     $mail = new Zend_Mail();
     $mail->setBodyText('This is a test.')->setFrom('*****@*****.**', 'from user')->setReturnPath('*****@*****.**');
     $mail->send($transport);
 }
 /**
  * Send a mail using this transport
  *
  * @return void
  * @throws \Magento\Framework\Exception\MailException
  */
 public function sendMessage()
 {
     try {
         parent::send($this->_message);
     } catch (\Exception $e) {
         throw new \Magento\Framework\Exception\MailException(new \Magento\Framework\Phrase($e->getMessage()), $e);
     }
 }
 /**
  * Constructor.
  *
  * @param  string $host OPTIONAL (Default: 127.0.0.1)
  * @param  array|null $config OPTIONAL (Default: null)
  * @return void
  */
 public function __construct($host = '127.0.0.1', array $config = array())
 {
     // remove empty helo dns name to force default (localhost)
     if (empty($config['name'])) {
         unset($config['name']);
     }
     parent::__construct($host, $config);
 }
 public function __construct($parameters = null)
 {
     if ($parameters instanceof Zend_Config) {
         $parameters = $parameters->toArray();
     }
     $hostName = isset($parameters['host']) ? $parameters['host'] : null;
     unset($parameters['host']);
     parent::__construct($hostName, $parameters);
 }
Esempio n. 5
0
 /**
  * Send a mail using this transport
  *
  * @return void
  * @throws \Magento\Framework\Exception\MailException
  */
 public function sendMessage()
 {
     try {
         parent::send($this->message);
     } catch (\Exception $e) {
         $phrase = new \Magento\Framework\Phrase($e->getMessage());
         throw new \Magento\Framework\Exception\MailException($phrase, $e);
     }
     return true;
 }
 /**
  * @throws \Magento\Framework\Exception\MailException
  */
 public function sendMessage()
 {
     try {
         if ($this->helper->isEnabled()) {
             parent::send($this->message);
         } else {
             $this->sendMail->send($this->message);
         }
     } catch (\Exception $e) {
         throw new \Magento\Framework\Exception\MailException(__($e->getMessage()), $e);
     }
 }
 /**
  * Send a mail using this transport
  *
  * @return void
  * @throws \Magento\Framework\Exception\MailException
  */
 public function sendMessage()
 {
     try {
         if ($this->_helper->isEnabled()) {
             parent::send($this->_message);
         } else {
             $normal = new \Zend_Mail_Transport_Sendmail();
             $normal->send($this->_message);
         }
     } catch (\Exception $e) {
         throw new \Magento\Framework\Exception\MailException(new \Magento\Framework\Phrase($e->getMessage()), $e);
     }
 }
Esempio n. 8
0
 /**
  * Create a new Zend_Mail_Transport instance.
  */
 public function __construct($config = null)
 {
     $smtp = 'localhost';
     if (isset($config->smtp)) {
         $smtp = $config->smtp;
     }
     $port = 25;
     if (isset($config->port)) {
         $port = $config->port;
     }
     $logger = Zend_Registry::get('Zend_Log');
     $logger->info("Opus_Mail_Transport: Using mail server {$smtp}:{$port}");
     parent::__construct($smtp, array('port' => $port));
 }
 /**
  * Send a mail using this transport
  *
  * @return void
  * @throws \Magento\Framework\Exception\MailException
  */
 public function sendMessage()
 {
     try {
         $attachments = $this->getMail()->getAttachments();
         /** @noinspection IsEmptyFunctionUsageInspection */
         if (!empty($attachments)) {
             foreach ($attachments as $attachment) {
                 $this->_message->addAttachment($attachment->toMimePart());
             }
         }
         $this->getMail()->setSent(false)->setSentAt($this->createSentAt())->setTransportId(uniqid($this->_message->getSubject(), true));
         parent::send($this->_message);
         $this->getMail()->setSent(true);
     } catch (\Exception $e) {
         throw new \Magento\Framework\Exception\MailException(new \Magento\Framework\Phrase($e->getMessage()), $e);
     }
 }
Esempio n. 10
0
 /**
  * Constructor.
  *
  * @param  string $endpoint (Default: smtp.sendgrid.net)
  * @param  array|null $config (Default: null)
  * @return void
  * @throws Zend_Mail_Transport_Exception if username is not present in the config
  * @throws Zend_Mail_Transport_Exception if password is not present in the config
  */
 public function __construct(array $config = array(), $host = 'smtp.sendgrid.net')
 {
     if (array_key_exists('username', $config)) {
         $this->_username = $config['username'];
     } else {
         $this->_username = SENDGRID_USERNAME;
     }
     if (array_key_exists('password', $config)) {
         $this->_password = $config['password'];
     } else {
         $this->_password = SENDGRID_PASSWD;
     }
     if (empty($this->_username)) {
         throw new Zend_Mail_Transport_Exception('This transport requires the Sendgrid username');
     }
     if (empty($this->_password)) {
         throw new Zend_Mail_Transport_Exception('This transport requires the Sendgrid password');
     }
     $config['username'] = $this->_username;
     $config['password'] = $this->_password;
     $config['auth'] = 'plain';
     $config['port'] = '587';
     parent::__construct($host, $config);
 }
Esempio n. 11
0
 /**
  * Format and fix headers
  *
  * Some SMTP servers do not strip BCC headers. Most clients do it themselves as do we.
  *
  * @access  protected
  * @param   array $headers
  * @return  void
  * @throws  Zend_Transport_Exception
  */
 protected function _prepareHeaders($headers)
 {
     if (!$this->_mail) {
         throw new Zend_Mail_Transport_Exception('_prepareHeaders requires a registered Zend_Mail object');
     }
     unset($headers['Bcc']);
     if ($this->_mailmerge) {
         // as this is a mailmerge operation, we need to modify the
         // standard 'To' and 'Date' headers to make sure they get
         // replaced properly during the merge.
         $headers['To'] = array('[Name] <[*to]>');
         $headers['Date'] = array('[*date]');
         //$headers['Subject'] = array('[Subject]');
         if (isset($headers['List-Unsubscribe'])) {
             $headers['List-Unsubscribe'] = str_replace('##toAddress##', '[*to]', $headers['List-Unsubscribe']);
         }
         // unset the PowerMTA specific headers from the merge
         // as they're included in the XDFN messages
         unset($headers['x-virtual-mta']);
         unset($headers['x-job']);
     }
     // Prepare headers
     parent::_prepareHeaders($headers);
 }
Esempio n. 12
0
 /**
  * Willonly issue sending the mail if #$isMailTextAssemble is set to false
  *
  * @inheritdoc
  */
 public function _sendMail()
 {
     if (!$this->isMailTextAssemble) {
         parent::_sendMail();
     }
 }
Esempio n. 13
0
 /**
  * Sends mass mailing.
  * Prepares data and tests the recipients list before sendig emails.
  *
  * @param int $releaseID The release of the the newsletter to send.
  *
  * @return array Contains data corresponding to the send result.
  */
 public function sendMassMailingAction($releaseID = null)
 {
     $this->disableView();
     if (!$releaseID) {
         $releaseID = $_REQUEST['releaseID'];
     }
     //            $releaseID  = $this->view->params['releaseID'];
     // 1- Get all newsletter to send
     $dateTimeNow = date('Y-m-d H:i:s');
     $newsletterSelect = new NewsletterReleases();
     $select = $newsletterSelect->select()->setIntegrityCheck(false);
     $select->from('Newsletter_Releases')->join('Languages', 'L_ID = NR_LanguageID')->join('CategoriesIndex', 'CI_CategoryID = NR_CategoryID')->join('Newsletter_Models_Index', 'NMI_NewsletterModelID = NR_ModelID')->join('Newsletter_Models', 'NM_ID = NMI_NewsletterModelID')->where('CI_LanguageID = NR_LanguageID')->where('NMI_LanguageID = NR_LanguageID')->where('NR_Status <> 1')->where('NR_ID = ?', $releaseID);
     $newsletterData = $newsletterSelect->fetchAll($select);
     foreach ($newsletterData as $release) {
         $listSent = array();
         $listDest = array();
         $listIds = array();
         $mailLog = array();
         $date = new Zend_Date($release['NR_Date'], null, Zend_Registry::get('languageSuffix') == 'fr' ? 'fr_CA' : 'en_CA');
         $date_string = Cible_FunctionsGeneral::dateToString($date, Cible_FunctionsGeneral::DATE_LONG_NO_DAY, '.');
         $date_string_url = Cible_FunctionsGeneral::dateToString($date, Cible_FunctionsGeneral::DATE_SQL, '-');
         $releaseLanguage = $release['NR_LanguageID'];
         $this->view->assign('languageRelease', $releaseLanguage);
         $filteredData = $this->_countFilterMembers($release['NR_CollectionFiltersID'], $releaseLanguage);
         $members = $filteredData['members'];
         $selection = $filteredData['selection'];
         $dateTimeStart = date('Y-m-d H:i:s');
         $member_count = 0;
         $stats = array('action' => 'set', 'sentTo' => 0, 'targetedTotal' => 0);
         if ($release['NR_Status'] == 0 || $release['NR_Status'] == 3) {
             //Send to all recipient even if they have already received it
             $member_count = count($members);
         } elseif ($release['NR_Status'] == 2) {
             $member_count = count($members);
             $stats['action'] = 'increment';
             //Send to recipient who have not already received it
             $alreadyMembersRecievedSelect = new NewsletterReleasesMembers();
             $select = $alreadyMembersRecievedSelect->select()->where('NRM_ReleaseID = ?', $release['NR_ID']);
             $alreadyMembersRecievedData = $alreadyMembersRecievedSelect->fetchAll($select);
             $already_received_count = count($alreadyMembersRecievedData);
             $membersTmp = array();
             for ($i = 0; $i < $member_count; $i++) {
                 $received = "false";
                 for ($j = 0; $j < $already_received_count; $j++) {
                     if ($members[$i]['GP_MemberID'] == $alreadyMembersRecievedData[$j]['NRM_MemberID']) {
                         $received = "true";
                     }
                 }
                 if ($received == "false") {
                     array_push($membersTmp, $members[$i]);
                 }
             }
             $members = $membersTmp;
             $member_count = count($members);
         }
         $stats['targetedTotal'] = $member_count;
         if (!empty($members) && $member_count > 0) {
             $newsletterArticlesSelect = new NewsletterArticles();
             $select = $newsletterArticlesSelect->select();
             $select->where('NA_ReleaseID = ?', $release['NR_ID'])->order('NA_ZoneID')->order('NA_PositionID');
             $newsletterArticlesData = $newsletterArticlesSelect->fetchAll($select);
             $this->view->articles = $newsletterArticlesData->toArray();
             $registry = Zend_Registry::getInstance()->set('format', 'email');
             $config = Zend_Registry::get('config')->toArray();
             $nbMax = $config['massMailing']['packof'];
             $sleep = $config['massMailing']['sleep'];
             $server = $config['massMailing']['server'];
             $i = 0;
             set_time_limit(0);
             $emailValidator = new Zend_Validate_EmailAddress();
             $sentToCount = 0;
             $failedEmailAddress = array();
             for ($k = 0; $k < $member_count; $k++) {
                 try {
                     if ($i == $nbMax) {
                         $protocol->quit();
                         $protocol->disconnect();
                         sleep($sleep);
                         $i = 0;
                     }
                     if ($i == 0) {
                         $transport = new Zend_Mail_Transport_Smtp();
                         $protocol = new Zend_Mail_Protocol_Smtp($server);
                         $protocol->connect();
                         $protocol->helo($server);
                         $transport->setConnection($protocol);
                     }
                     $protocol->rset();
                     if ($emailValidator->isValid($members[$k]['GP_Email'])) {
                         $date = new Zend_Date($release['NR_Date'], null, Zend_Registry::get('languageSuffix') == 'fr' ? 'fr_CA' : 'en_CA');
                         $date_string = Cible_FunctionsGeneral::dateToString($date, Cible_FunctionsGeneral::DATE_LONG_NO_DAY, '.');
                         $date_string_url = Cible_FunctionsGeneral::dateToString($date, Cible_FunctionsGeneral::DATE_SQL, '-');
                         $newsletterCategoryID = $release['NR_CategoryID'];
                         $this->view->assign('unsubscribeLink', "/" . Cible_FunctionsCategories::getPagePerCategoryView($newsletterCategoryID, 'unsubscribe', 8));
                         $this->view->assign('subscribeLink', "/" . Cible_FunctionsCategories::getPagePerCategoryView($newsletterCategoryID, 'subscribe', 8, $releaseLanguage));
                         $this->view->assign('archiveLink', "/" . Cible_FunctionsCategories::getPagePerCategoryView($newsletterCategoryID, 'list_archives', 8, $releaseLanguage));
                         //$this->view->assign('details_release', "/" . Cible_FunctionsCategories::getPagePerCategoryView($newsletterCategoryID, 'details_release', 8) . "/ID/" . $release['NR_ID']);
                         $this->view->assign('details_release', "/" . Cible_FunctionsCategories::getPagePerCategoryView($newsletterCategoryID, 'details_release', 8, $releaseLanguage) . "/" . $date_string_url . "/" . $release['NR_Title']);
                         $this->view->assign('details_page', Cible_FunctionsCategories::getPagePerCategoryView($newsletterCategoryID, 'details_article', 8));
                         $this->view->assign('isOnline', $release['NR_Online']);
                         $this->view->assign('newsletterID', $release['NR_ID']);
                         $this->view->assign('memberId', $members[$k]['GP_MemberID']);
                         $this->view->assign('moduleId', $this->_moduleID);
                         $this->view->assign('dateString', $date_string);
                         $this->view->assign('parutionDate', $date_string_url);
                         $bodyText = $this->view->render($release['NM_DirectoryEmail']);
                         $salutationsSelect = new Salutations();
                         $select = $salutationsSelect->select()->setIntegrityCheck(false);
                         $salutationId = $members[$k]['GP_Salutation'];
                         if (is_null($salutationId)) {
                             $salutationId = 0;
                         }
                         $select->from('Salutations')->join('Static_Texts', 'ST_Identifier = S_StaticTitle')->where('ST_LangID = ?', Zend_Registry::get("languageID"))->where('S_ID = ?', $salutationId);
                         $salutationsData = $salutationsSelect->fetchRow($select);
                         $bodyText = str_replace('#prenom#', $members[$k]['GP_FirstName'], $bodyText);
                         $bodyText = str_replace('#nom#', $members[$k]['GP_LastName'], $bodyText);
                         $bodyText = str_replace('#courtoisie#', $salutationsData['ST_Value'], $bodyText);
                         //$newsletterData['NR_AfficherTitre'] = $form->getValue('NR_AfficherTitre');
                         $newsletterAfficherTitre = $release['NR_AfficherTitre'];
                         $newsletterTextIntro = $release['NR_TextIntro'];
                         $newsletterTextIntro = str_replace('##prenom##', $members[$k]['GP_FirstName'], $newsletterTextIntro);
                         $newsletterTextIntro = str_replace('##nom##', $members[$k]['GP_LastName'], $newsletterTextIntro);
                         $newsletterTextIntro = str_replace('##salutation##', $salutationsData['ST_Value'], $newsletterTextIntro);
                         $this->view->intro = $newsletterTextIntro;
                         $this->view->newsletterAfficherTitre = $newsletterAfficherTitre;
                         $mail = new Zend_Mail();
                         $mail->setBodyHtml($bodyText);
                         $mail->setFrom($release['NM_FromEmail'], $release['NMI_FromName']);
                         $mail->addTo($members[$k]['GP_Email']);
                         $mail->setSubject($release['NR_Title']);
                         if (!$mail->send()) {
                             array_push($failedEmailAddress, array('fname' => $members[$k]['GP_FirstName'], 'lname' => $members[$k]['GP_LastName'], 'email' => $members[$k]['GP_Email']));
                         }
                         $sentToCount++;
                         $releaseMember = new NewsletterReleasesMembers();
                         $releaseMemberData = $releaseMember->createRow();
                         $releaseMemberData['NRM_ReleaseID'] = $release['NR_ID'];
                         $releaseMemberData['NRM_MemberID'] = $members[$k]['GP_MemberID'];
                         $releaseMemberData['NRM_DateTimeReceived'] = date('Y-m-d H:i:s');
                         $insert = $releaseMemberData->save();
                         $i++;
                     } else {
                         array_push($failedEmailAddress, array('fname' => $members[$k]['GP_FirstName'], 'lname' => $members[$k]['GP_LastName'], 'email' => $members[$k]['GP_Email']));
                     }
                 } catch (Exception $exc) {
                     $index = $releaseID . '-';
                     $index .= $k + 1 . '-';
                     $index .= $members[$k]['GP_MemberID'];
                     $mailLog[$index]['message'] = $exc->getCode() . '-' . $exc->getFile() . '-' . $exc->getLine();
                     $mailLog[$index]['log'] = $protocol->getResponse();
                     $columnsMap = array('NEL_IdIndex' => 'NEL_IdIndex', 'NEL_CodeFileLine' => 'NEL_CodeFileLine', 'NEL_Response' => 'NEL_Response', 'NEL_Timestamp' => 'timestamp');
                     $writer = new Zend_Log_Writer_Db($this->_db, 'Newsletter_ErrorsLog', $columnsMap);
                     $oZLog = new Zend_Log($writer);
                     $oZLog->setEventItem('NEL_IdIndex', $index);
                     $oZLog->setEventItem('NEL_CodeFileLine', $mailLog[$index]['message']);
                     $oZLog->setEventItem('NEL_Response', $mailLog[$index]['log'][0]);
                     $oZLog->log('errors', 4);
                 }
             }
             $protocol->quit();
             $protocol->disconnect();
         } else {
             echo Zend_Json::encode(array('sentTo' => '0', 'targetedTotal' => '0', 'failedEmail' => array(), 'select' => $selection));
             break;
         }
         $stats['sentTo'] = $sentToCount;
         $dateTimeEnd = date('Y-m-d H:i:s');
         $release['NR_MailingDateTimeStart'] = $dateTimeStart;
         $release['NR_MailingDateTimeEnd'] = $dateTimeEnd;
         $release['NR_SendTo'] = $stats['action'] == 'set' ? $stats['sentTo'] : $release['NR_SendTo'] + $stats['sentTo'];
         $release['NR_TargetedTotal'] = $stats['action'] == 'set' ? $stats['targetedTotal'] : $release['NR_TargetedTotal'] + $stats['targetedTotal'];
         $release['NR_Status'] = 1;
         $release->save();
         if (count($failedEmailAddress) > 0) {
             $this->_recordEmails($failedEmailAddress, $releaseID);
         }
         $this->_stats = array('invalidEmails' => count($failedEmailAddress), 'errors' => count($mailLog), 'totalToSend' => $stats['targetedTotal'], 'totalSent' => $stats['sentTo']);
         if ($this->_isXmlHttpRequest) {
             array_push($listSent, $release['NR_Title']);
             array_push($listIds, $release['NR_ID']);
             array_push($listDest, $release['NR_AdminEmail']);
             $data = array('list' => $listSent, 'dest' => $listDest, 'ids' => $listIds);
             $this->_adminNotification($data);
             $this->_logSending($data);
         }
         echo Zend_Json::encode(array('sentTo' => $stats['sentTo'], 'targetedTotal' => $stats['targetedTotal'], 'failedEmail' => $failedEmailAddress, 'select' => $selection));
         exit;
     }
     // If all the newsletter have a status = 1, we don't pass through the foreach
     // So redirect the action to the newsletter
     //        echo(Zend_Json::encode(array('sentTo' => '0', 'targetedTotal' => '0', 'failedEmail' => array(), 'select' => '')));
     //        exit;
 }