setReturnPath() public method

Sets the Return-Path header of the message
public setReturnPath ( string $email ) : Zend_Mail
$email string
return Zend_Mail Provides fluent interface
Beispiel #1
0
 protected function _sendEmail(array $email, array $user, Zend_Mail_Transport_Abstract $transport)
 {
     if (!$user['email']) {
         return;
     }
     $phraseTitles = XenForo_Helper_String::findPhraseNamesFromStringSimple($email['email_title'] . $email['email_body']);
     /** @var XenForo_Model_Phrase $phraseModel */
     $phraseModel = XenForo_Model::create('XenForo_Model_Phrase');
     $phrases = $phraseModel->getPhraseTextFromPhraseTitles($phraseTitles, $user['language_id']);
     foreach ($phraseTitles as $search => $phraseTitle) {
         if (isset($phrases[$phraseTitle])) {
             $email['email_title'] = str_replace($search, $phrases[$phraseTitle], $email['email_title']);
             $email['email_body'] = str_replace($search, $phrases[$phraseTitle], $email['email_body']);
         }
     }
     $mailObj = new Zend_Mail('utf-8');
     $mailObj->setSubject($email['email_title'])->addTo($user['email'], $user['username'])->setFrom($email['from_email'], $email['from_name']);
     $options = XenForo_Application::getOptions();
     $bounceEmailAddress = $options->bounceEmailAddress;
     if (!$bounceEmailAddress) {
         $bounceEmailAddress = $options->defaultEmailAddress;
     }
     $toEmail = $user['email'];
     $bounceHmac = substr(hash_hmac('md5', $toEmail, XenForo_Application::getConfig()->globalSalt), 0, 8);
     $mailObj->addHeader('X-To-Validate', "{$bounceHmac}+{$toEmail}");
     if ($options->enableVerp) {
         $verpValue = str_replace('@', '=', $toEmail);
         $bounceEmailAddress = str_replace('@', "+{$bounceHmac}+{$verpValue}@", $bounceEmailAddress);
     }
     $mailObj->setReturnPath($bounceEmailAddress);
     if ($email['email_format'] == 'html') {
         $replacements = array('{name}' => htmlspecialchars($user['username']), '{email}' => htmlspecialchars($user['email']), '{id}' => $user['user_id']);
         $email['email_body'] = strtr($email['email_body'], $replacements);
         $text = trim(htmlspecialchars_decode(strip_tags($email['email_body'])));
         $mailObj->setBodyHtml($email['email_body'])->setBodyText($text);
     } else {
         $replacements = array('{name}' => $user['username'], '{email}' => $user['email'], '{id}' => $user['user_id']);
         $email['email_body'] = strtr($email['email_body'], $replacements);
         $mailObj->setBodyText($email['email_body']);
     }
     if (!$mailObj->getMessageId()) {
         $mailObj->setMessageId();
     }
     $thisTransport = XenForo_Mail::getFinalTransportForMail($mailObj, $transport);
     try {
         $mailObj->send($thisTransport);
     } catch (Exception $e) {
         if (method_exists($thisTransport, 'resetConnection')) {
             XenForo_Error::logException($e, false, "Email to {$user['email']} failed: ");
             $thisTransport->resetConnection();
             try {
                 $mailObj->send($thisTransport);
             } catch (Exception $e) {
                 XenForo_Error::logException($e, false, "Email to {$user['email']} failed (after retry): ");
             }
         } else {
             XenForo_Error::logException($e, false, "Email to {$user['email']} failed: ");
         }
     }
 }
Beispiel #2
0
 /**
  * Send all messages in a queue
  *
  * @return Mage_Core_Model_Email_Queue
  */
 public function send()
 {
     /** @var $collection Mage_Core_Model_Resource_Email_Queue_Collection */
     $collection = Mage::getModel('core/email_queue')->getCollection()->addOnlyForSendingFilter()->setPageSize(self::MESSAGES_LIMIT_PER_CRON_RUN)->setCurPage(1)->load();
     ini_set('SMTP', Mage::getStoreConfig('system/smtp/host'));
     ini_set('smtp_port', Mage::getStoreConfig('system/smtp/port'));
     /** @var $message Mage_Core_Model_Email_Queue */
     foreach ($collection as $message) {
         if ($message->getId()) {
             $parameters = new Varien_Object($message->getMessageParameters());
             if ($parameters->getReturnPathEmail() !== null) {
                 $mailTransport = new Zend_Mail_Transport_Sendmail("-f" . $parameters->getReturnPathEmail());
                 Zend_Mail::setDefaultTransport($mailTransport);
             }
             $mailer = new Zend_Mail('utf-8');
             foreach ($message->getRecipients() as $recipient) {
                 list($email, $name, $type) = $recipient;
                 switch ($type) {
                     case self::EMAIL_TYPE_BCC:
                         $mailer->addBcc($email, '=?utf-8?B?' . base64_encode($name) . '?=');
                         break;
                     case self::EMAIL_TYPE_TO:
                     case self::EMAIL_TYPE_CC:
                     default:
                         $mailer->addTo($email, '=?utf-8?B?' . base64_encode($name) . '?=');
                         break;
                 }
             }
             if ($parameters->getIsPlain()) {
                 $mailer->setBodyText($message->getMessageBody());
             } else {
                 $mailer->setBodyHTML($message->getMessageBody());
             }
             $mailer->setSubject('=?utf-8?B?' . base64_encode($parameters->getSubject()) . '?=');
             $mailer->setFrom($parameters->getFromEmail(), $parameters->getFromName());
             if ($parameters->getReplyTo() !== null) {
                 $mailer->setReplyTo($parameters->getReplyTo());
             }
             if ($parameters->getReturnTo() !== null) {
                 $mailer->setReturnPath($parameters->getReturnTo());
             }
             try {
                 //$mailer->send();
                 $mailer->send(Mage::helper('smtp')->getTransport());
                 unset($mailer);
                 $message->setProcessedAt(Varien_Date::formatDate(true));
                 $message->save();
             } catch (Exception $e) {
                 unset($mailer);
                 $oldDevMode = Mage::getIsDeveloperMode();
                 Mage::setIsDeveloperMode(true);
                 Mage::logException($e);
                 Mage::setIsDeveloperMode($oldDevMode);
                 return false;
             }
         }
     }
     return $this;
 }
Beispiel #3
0
 public static function send($email, $name, $subject, $view, $data, $containerViewFile = 'mail')
 {
     self::init();
     if (is_object($data)) {
         $data->email = $email;
         $data->subject = $subject;
     } else {
         if (is_array($data)) {
             $data['email'] = $email;
             $data['subject'] = $subject;
         } else {
             $data = array();
             $data['email'] = $email;
             $data['subject'] = $subject;
         }
     }
     if (Settings::get(Settings::DEBUG, false) && Settings::get(self::TEST_MAIL, '') != '') {
         $email = Settings::get(self::TEST_MAIL, '');
     }
     $html = self::preview($view, $data, $containerViewFile, false);
     $text = trim(self::preview($view, $data, $containerViewFile, true));
     if (String::isHtml($text) || $text == '') {
         $text = T("This is an HTML message. Please use a HTML capable mail program to read this message.");
     }
     $mail = new Zend_Mail(Settings::get(Settings::ENCODING));
     $fromName = Settings::get(self::FROM_NAME);
     $fromMail = Settings::get(self::FROM_MAIL);
     $mail->setFrom($fromMail, $fromName);
     $mail->setReplyTo(Settings::get(self::REPLY_MAIL, $fromMail), $fromName);
     $mail->setReturnPath(Settings::get(self::RETURN_MAIL, $fromMail), $fromName);
     $mail->setSubject($subject);
     $mail->setBodyHtml($html);
     $mail->addTo($email, $name);
     $mail->setBodyText($text);
     if (Settings::get(self::SELF_EMAIL, false)) {
         $mail->addBcc(Settings::get(self::SELF_EMAIL));
     }
     $mail->send();
 }
 /**
  * Функция настроена для отправки сообщений через mail.russ-call.ru
  * ИСПРАВЛЯТЬ ОСТОРОЖНО! Может не доставляться почта или сообщения
  * пойдут в спам
  *
  * @param Forum_Model_Forum $post
  * @return $this
  */
 public function sendAdminMail(Forum_Model_Forum $post)
 {
     $mailToAdmin = new Zend_Mail("utf-8");
     //$mailToAdmin->setFrom($post->getEmail(), $post->getAuthor());
     $mailToAdmin->setFrom("*****@*****.**", "Alpha-Hydro");
     $mailToAdmin->setSubject("Alpha-Hydro.Forum.");
     $mailToAdmin->setReturnPath("*****@*****.**");
     $textHtml = '<p>Автор: ' . $post->getAuthor() . ' (' . $post->getEmail() . ')</p>';
     $textHtml .= '<p>Категория: ' . $post->getCategory() . '</p>';
     $textHtml .= '<p><b>Сообщение:</b></p>';
     $textHtml .= $post->getContent();
     $mailToAdmin->setBodyHtml($textHtml);
     //$mailToAdmin->addTo("*****@*****.**", "Alpha-Hydro");
     $mailToAdmin->addTo("*****@*****.**", "Alpha-Hydro");
     $mailToAdmin->addBcc(array("*****@*****.**", "*****@*****.**", "*****@*****.**"));
     //$mailToAdmin->addBcc('*****@*****.**');
     $mailToAdmin->send();
     return $this;
 }
 public static function execute($subject, $to, $from, $body)
 {
     if (!$to) {
         return false;
     }
     self::initialize();
     opApplicationConfiguration::registerZend();
     $subject = mb_convert_kana($subject, 'KV');
     $mailer = new Zend_Mail('iso-2022-jp');
     $mailer->setHeaderEncoding(Zend_Mime::ENCODING_BASE64)->setFrom($from)->addTo($to)->setSubject(mb_encode_mimeheader($subject, 'iso-2022-jp'))->setBodyText(mb_convert_encoding($body, 'JIS', 'UTF-8'), 'iso-2022-jp', Zend_Mime::ENCODING_7BIT);
     if ($envelopeFrom = sfConfig::get('op_mail_envelope_from')) {
         $mailer->setReturnPath($envelopeFrom);
     }
     $result = $mailer->send();
     Zend_Loader::registerAutoLoad('Zend_Loader', false);
     return $result;
 }
Beispiel #6
0
 protected function _sendEmail(array $user, array $email, Zend_Mail_Transport_Abstract $transport)
 {
     if (!$user['email']) {
         return false;
     }
     if (!XenForo_Application::get('config')->enableMail) {
         return true;
     }
     $options = XenForo_Application::getOptions();
     XenForo_Db::ping();
     $mailObj = new Zend_Mail('utf-8');
     $mailObj->setSubject($email['email_title'])->addTo($user['email'], $user['username'])->setFrom($email['from_email'], $email['from_name']);
     $bounceEmailAddress = $options->bounceEmailAddress;
     if (!$bounceEmailAddress) {
         $bounceEmailAddress = $options->defaultEmailAddress;
     }
     $toEmail = $user['email'];
     $bounceHmac = substr(hash_hmac('md5', $toEmail, XenForo_Application::getConfig()->globalSalt), 0, 8);
     $mailObj->addHeader('X-To-Validate', "{$bounceHmac}+{$toEmail}");
     if ($options->enableVerp) {
         $verpValue = str_replace('@', '=', $toEmail);
         $bounceEmailAddress = str_replace('@', "+{$bounceHmac}+{$verpValue}@", $bounceEmailAddress);
     }
     $mailObj->setReturnPath($bounceEmailAddress);
     if ($email['email_format'] == 'html') {
         $replacements = array('{name}' => htmlspecialchars($user['username']), '{email}' => htmlspecialchars($user['email']), '{id}' => $user['user_id']);
         $email['email_body'] = strtr($email['email_body'], $replacements);
         $text = trim(htmlspecialchars_decode(strip_tags($email['email_body'])));
         $mailObj->setBodyHtml($email['email_body'])->setBodyText($text);
     } else {
         $replacements = array('{name}' => $user['username'], '{email}' => $user['email'], '{id}' => $user['user_id']);
         $email['email_body'] = strtr($email['email_body'], $replacements);
         $mailObj->setBodyText($email['email_body']);
     }
     if (!$mailObj->getMessageId()) {
         $mailObj->setMessageId();
     }
     $thisTransport = XenForo_Mail::getFinalTransportForMail($mailObj, $transport);
     try {
         $mailObj->send($thisTransport);
     } catch (Exception $e) {
         XenForo_Error::logException($e, false, "Email to {$user['email']} failed: ");
         return false;
     }
     return true;
 }
Beispiel #7
0
 /**
  * Gets the fully prepared, internal mail object. This can be called directly
  * to allow advanced manipulation before sending
  *
  * @param string $toEmail The email address the email is sent to
  * @param string $toName Name of the person receiving it
  * @param array $headers List of additional headers to send
  * @param string $fromEmail Email address the email should come from; if not specified, uses board default
  * @param string $fromName Name the email should come from; if not specified, uses board default
  * @param string $returnPath The return path of the email (where bounces should go to)
  *
  * @return Zend_Mail|false
  */
 public function getPreparedMailHandler($toEmail, $toName = '', array $headers = array(), $fromEmail = '', $fromName = '', $returnPath = '')
 {
     if (!$toEmail) {
         return false;
     }
     $contents = $this->prepareMailContents();
     if (!$contents) {
         return false;
     }
     $contents = $this->wrapMailContainer($contents['subject'], $contents['bodyText'], $contents['bodyHtml']);
     $mailObj = new Zend_Mail('utf-8');
     $mailObj->setSubject($contents['subject'])->setBodyText($contents['bodyText'])->addTo($toEmail, $toName);
     if ($contents['bodyHtml'] !== '') {
         $mailObj->setBodyHtml($contents['bodyHtml']);
     }
     $options = XenForo_Application::getOptions();
     if (!$fromName) {
         $fromName = $options->emailSenderName ? $options->emailSenderName : $options->boardTitle;
     }
     if ($fromEmail) {
         $mailObj->setFrom($fromEmail, $fromName);
     } else {
         $mailObj->setFrom($options->defaultEmailAddress, $fromName);
     }
     if ($returnPath) {
         $mailObj->setReturnPath($returnPath);
     } else {
         $bounceEmailAddress = $options->bounceEmailAddress;
         if (!$bounceEmailAddress) {
             $bounceEmailAddress = $options->defaultEmailAddress;
         }
         $bounceHmac = substr(hash_hmac('md5', $toEmail, XenForo_Application::getConfig()->globalSalt), 0, 8);
         $mailObj->addHeader('X-To-Validate', "{$bounceHmac}+{$toEmail}");
         if ($options->enableVerp) {
             $verpValue = str_replace('@', '=', $toEmail);
             $bounceEmailAddress = str_replace('@', "+{$bounceHmac}+{$verpValue}@", $bounceEmailAddress);
         }
         $mailObj->setReturnPath($bounceEmailAddress);
     }
     foreach ($headers as $headerName => $headerValue) {
         if (isset(self::$_headerMap[strtolower($headerName)])) {
             $func = self::$_headerMap[strtolower($headerName)];
             $mailObj->{$func}($headerValue);
         } else {
             $mailObj->addHeader($headerName, $headerValue);
         }
     }
     if (!$mailObj->getMessageId()) {
         $mailObj->setMessageId();
     }
     return $mailObj;
 }
 public function setReturnPath($email)
 {
     parent::clearReturnPath();
     return parent::setReturnPath($email);
 }
Beispiel #9
0
 public function save()
 {
     $subject = $this->_options['email_subject_template']['option_value'];
     $recipient = trim($this->_options['email_recipient_email']['option_value']);
     if (strpos($recipient, ',') !== false) {
         $recipient = explode(',', $recipient);
         foreach ($recipient as &$recip) {
             $recip = trim($recip);
         }
     }
     $sender = trim($this->_options['email_sender_email']['option_value']);
     $format = $this->_options['email_format']['option_value'];
     // default to visitor's e-mail address, but stop execution for guests
     if ($sender == '') {
         if (!XenForo_Visitor::getUserId()) {
             return false;
         } else {
             $sender = XenForo_Visitor::getInstance()->email;
         }
     }
     if ($this->_options['email_message_template']['option_value'] == '') {
         $message = '';
         foreach ($this->_templateFields as $field) {
             if ($this->_options['email_hide_empty_fields']['option_value'] == array() || $this->_options['email_hide_empty_fields']['option_value'] !== array() && $field['value'] != '') {
                 $message .= $field['title'] . ': ' . $field['value'] . PHP_EOL;
             }
         }
     } else {
         $message = $this->_options['email_message_template']['option_value'];
     }
     $transport = XenForo_Mail::getDefaultTransport();
     $mailObj = new Zend_Mail('utf-8');
     $mailObj->setSubject($subject)->addTo($recipient)->setFrom(XenForo_Application::getOptions()->defaultEmailAddress)->setReplyTo($sender);
     if ($this->_attachmentHash) {
         $attachmentModel = XenForo_Model::create('XenForo_Model_Attachment');
         $attachments = $attachmentModel->getAttachmentsByTempHash($this->_attachmentHash);
         foreach ($attachments as $attachmentId => $attachment) {
             $attachmentData = $attachmentModel->getAttachmentDataById($attachment['data_id']);
             $attachmentDataFile = $attachmentModel->getAttachmentDataFilePath($attachmentData);
             $fileOutput = new XenForo_FileOutput($attachmentDataFile);
             $mailAttachment = $mailObj->createAttachment($fileOutput->getContents());
             $mailAttachment->filename = $attachmentData['filename'];
             // delete the attachment as it is no longer needed
             $dw = XenForo_DataWriter::create('XenForo_DataWriter_Attachment');
             $dw->setExistingData($attachment);
             $dw->delete();
         }
     }
     $options = XenForo_Application::get('options');
     $bounceEmailAddress = $options->bounceEmailAddress;
     if (!$bounceEmailAddress) {
         $bounceEmailAddress = $options->defaultEmailAddress;
     }
     $mailObj->setReturnPath($bounceEmailAddress);
     // create plain text message
     $bbCodeParserText = new XenForo_BbCode_Parser(XenForo_BbCode_Formatter_Base::create('Text'));
     $messageText = new XenForo_BbCode_TextWrapper($message, $bbCodeParserText);
     if ($format == 'html') {
         // create html message
         $bbCodeParserHtml = new XenForo_BbCode_Parser(XenForo_BbCode_Formatter_Base::create('HtmlEmail'));
         $messageHtml = new XenForo_BbCode_TextWrapper($message, $bbCodeParserHtml);
         $mailObj->setBodyHtml(htmlspecialchars_decode($messageHtml))->setBodyText($messageText);
     } else {
         $mailObj->setBodyText($messageText);
     }
     $mailObj->send($transport);
 }
Beispiel #10
0
 protected function _sendConfirmEmail($emailAddress)
 {
     $confirm = new AccountConfirm();
     $confirm->emailAddress = $emailAddress;
     $confirm->save();
     $this->view->layout()->setLayout('blank');
     $this->view->assign('emailAddress', $confirm->emailAddress);
     $this->view->assign('confirmCode', $confirm->code);
     $link = $this->_helper->url('confirm', 'account', 'default', array('email' => $confirm->emailAddress, 'code' => $confirm->code));
     $this->view->assign('link', "http://{$this->_config->hostname}/{$link}");
     $mail = new Zend_Mail();
     $mail->addTo($confirm->emailAddress);
     $mail->setBodyText($this->view->render('mail/confirm-text.phtml'));
     $mail->setBodyHtml($this->view->render('mail/confirm-html.phtml'));
     $mail->setFrom('accounts@' . $this->_config->hostname, 'BitNotion, M.D.');
     $mail->setReturnPath('no-reply@' . $this->_config->hostname);
     $mail->setSubject('BitNotion | Please Confirm Your E-Mail Address');
     $mail->send();
 }
Beispiel #11
0
 public static function execute($subject, $to, $from, $body)
 {
     if (!$to) {
         return false;
     }
     self::initialize();
     opApplicationConfiguration::registerZend();
     $subject = mb_convert_kana($subject, 'KV');
     $mailer = new Zend_Mail('iso-2022-jp');
     $mailer->setHeaderEncoding(Zend_Mime::ENCODING_BASE64)->setFrom($from)->addTo($to)->setSubject(mb_encode_mimeheader($subject, 'iso-2022-jp'))->setBodyText(mb_convert_encoding($body, 'JIS', 'UTF-8'), 'iso-2022-jp', Zend_Mime::ENCODING_7BIT);
     if ($envelopeFrom = sfConfig::get('op_mail_envelope_from')) {
         $mailer->setReturnPath($envelopeFrom);
     }
     try {
         $result = $mailer->send();
     } catch (Zend_Mail_Protocol_Exception $e) {
         if (sfContext::getInstance()->getActionName() === null) {
             error_log('Mail Send Error');
         } else {
             $action = sfContext::getInstance()->getActionStack()->getFirstEntry()->getActionInstance();
             $action->redirect('default/mailError');
         }
     }
     Zend_Loader::registerAutoLoad('Zend_Loader', false);
     return $result;
 }
Beispiel #12
0
 public function testReturnPath()
 {
     $mail = new Zend_Mail();
     $res = $mail->setBodyText('This is a test.');
     $mail->setFrom('*****@*****.**', 'test Mail User');
     $mail->setSubject('My Subject');
     $mail->addTo('*****@*****.**');
     $mail->addTo('*****@*****.**');
     $mail->addBcc('*****@*****.**');
     $mail->addBcc('*****@*****.**');
     $mail->addCc('*****@*****.**', 'Example no. 1 for cc');
     $mail->addCc('*****@*****.**', 'Example no. 2 for cc');
     // First example: from and return-path should be equal
     $mock = new Zend_Mail_Transport_Mock();
     $mail->send($mock);
     $this->assertTrue($mock->called);
     $this->assertEquals($mail->getFrom(), $mock->returnPath);
     // Second example: from and return-path should not be equal
     $mail->setReturnPath('*****@*****.**');
     $mock = new Zend_Mail_Transport_Mock();
     $mail->send($mock);
     $this->assertTrue($mock->called);
     $this->assertNotEquals($mail->getFrom(), $mock->returnPath);
     $this->assertEquals($mail->getReturnPath(), $mock->returnPath);
     $this->assertNotEquals($mock->returnPath, $mock->from);
 }
Beispiel #13
0
 protected function _sendEmail(array $user, array $email, Zend_Mail_Transport_Abstract $transport)
 {
     if (!$user['email']) {
         return false;
     }
     $mailObj = new Zend_Mail('utf-8');
     $mailObj->setSubject($email['email_title'])->addTo($user['email'], $user['username'])->setFrom($email['from_email'], $email['from_name']);
     $options = XenForo_Application::get('options');
     $bounceEmailAddress = $options->bounceEmailAddress;
     if (!$bounceEmailAddress) {
         $bounceEmailAddress = $options->defaultEmailAddress;
     }
     $mailObj->setReturnPath($bounceEmailAddress);
     if ($email['email_format'] == 'html') {
         $replacements = array('{name}' => htmlspecialchars($user['username']), '{email}' => htmlspecialchars($user['email']), '{id}' => $user['user_id']);
         $email['email_body'] = strtr($email['email_body'], $replacements);
         $text = trim(htmlspecialchars_decode(strip_tags($email['email_body'])));
         $mailObj->setBodyHtml($email['email_body'])->setBodyText($text);
     } else {
         $replacements = array('{name}' => $user['username'], '{email}' => $user['email'], '{id}' => $user['user_id']);
         $email['email_body'] = strtr($email['email_body'], $replacements);
         $mailObj->setBodyText($email['email_body']);
     }
     try {
         $mailObj->send($transport);
     } catch (Exception $e) {
         return false;
     }
     return true;
 }
 public function execute(array $deferred, array $data, $targetRunTime, &$status)
 {
     $data = array_merge(array('start' => 0, 'count' => 0, 'criteria' => null, 'userIds' => null, 'email' => array()), $data);
     if (!XenForo_Application::get('config')->enableMail) {
         return false;
     }
     $s = microtime(true);
     /* @var $userModel XenForo_Model_User */
     $userModel = XenForo_Model::create('XenForo_Model_User');
     if (is_array($data['criteria'])) {
         $userIds = $userModel->getUserIds($data['criteria'], $data['start'], 1000);
     } else {
         if (is_array($data['userIds'])) {
             $userIds = $data['userIds'];
         } else {
             $userIds = array();
         }
     }
     if (!$userIds) {
         return false;
     }
     $options = XenForo_Application::getOptions();
     $email = $data['email'];
     $transport = XenForo_Mail::getTransport();
     $limitTime = $targetRunTime > 0;
     foreach ($userIds as $key => $userId) {
         $data['count']++;
         $data['start'] = $userId;
         unset($userIds[$key]);
         $user = $userModel->getUserById($userId);
         if (!$user['email']) {
             continue;
         }
         $phraseTitles = XenForo_Helper_String::findPhraseNamesFromStringSimple($email['email_title'] . $email['email_body']);
         /** @var XenForo_Model_Phrase $phraseModel */
         $phraseModel = XenForo_Model::create('XenForo_Model_Phrase');
         $phrases = $phraseModel->getPhraseTextFromPhraseTitles($phraseTitles, $user['language_id']);
         foreach ($phraseTitles as $search => $phraseTitle) {
             if (isset($phrases[$phraseTitle])) {
                 $email['email_title'] = str_replace($search, $phrases[$phraseTitle], $email['email_title']);
                 $email['email_body'] = str_replace($search, $phrases[$phraseTitle], $email['email_body']);
             }
         }
         $mailObj = new Zend_Mail('utf-8');
         $mailObj->setSubject($email['email_title'])->addTo($user['email'], $user['username'])->setFrom($email['from_email'], $email['from_name']);
         $bounceEmailAddress = $options->bounceEmailAddress;
         if (!$bounceEmailAddress) {
             $bounceEmailAddress = $options->defaultEmailAddress;
         }
         $toEmail = $user['email'];
         $bounceHmac = substr(hash_hmac('md5', $toEmail, XenForo_Application::getConfig()->globalSalt), 0, 8);
         $mailObj->addHeader('X-To-Validate', "{$bounceHmac}+{$toEmail}");
         if ($options->enableVerp) {
             $verpValue = str_replace('@', '=', $toEmail);
             $bounceEmailAddress = str_replace('@', "+{$bounceHmac}+{$verpValue}@", $bounceEmailAddress);
         }
         $mailObj->setReturnPath($bounceEmailAddress);
         if ($email['email_format'] == 'html') {
             $replacements = array('{name}' => htmlspecialchars($user['username']), '{email}' => htmlspecialchars($user['email']), '{id}' => $user['user_id']);
             $email['email_body'] = strtr($email['email_body'], $replacements);
             $text = trim(htmlspecialchars_decode(strip_tags($email['email_body'])));
             $mailObj->setBodyHtml($email['email_body'])->setBodyText($text);
         } else {
             $replacements = array('{name}' => $user['username'], '{email}' => $user['email'], '{id}' => $user['user_id']);
             $email['email_body'] = strtr($email['email_body'], $replacements);
             $mailObj->setBodyText($email['email_body']);
         }
         if (!$mailObj->getMessageId()) {
             $mailObj->setMessageId();
         }
         $thisTransport = XenForo_Mail::getFinalTransportForMail($mailObj, $transport);
         try {
             $mailObj->send($thisTransport);
         } catch (Exception $e) {
             XenForo_Error::logException($e, false, "Email to {$user['email']} failed: ");
             continue;
         }
         if ($limitTime && microtime(true) - $s > $targetRunTime) {
             break;
         }
     }
     if (is_array($data['userIds'])) {
         $data['userIds'] = $userIds;
     }
     $actionPhrase = new XenForo_Phrase('emailing');
     $typePhrase = new XenForo_Phrase('users');
     $status = sprintf('%s... %s (%d)', $actionPhrase, $typePhrase, $data['count']);
     return $data;
 }
 public function send()
 {
     $_helper = Mage::helper('smtppro');
     // if we have a valid queue page size override, use it
     if (is_numeric($_helper->getQueuePerCron()) && intval($_helper->getQueuePerCron()) > 0) {
         $percron = $_helper->getQueuePerCron();
         $_helper->log('SMTP Pro using queue override page size: ' . $percron);
     } else {
         $percron = self::MESSAGES_LIMIT_PER_CRON_RUN;
     }
     $pauseMicros = 0;
     // if we have a valid pause, use it
     if (is_numeric($_helper->getQueuePause()) && intval($_helper->getQueuePause()) > 0) {
         $pauseMicros = $_helper->getQueuePause() * 1000;
         // * 1000 for millis => micros
         $_helper->log('SMTP Pro using queue override pause: ' . $pauseMicros);
     }
     /** @var $collection Mage_Core_Model_Resource_Email_Queue_Collection */
     $collection = Mage::getModel('core/email_queue')->getCollection()->addOnlyForSendingFilter()->setPageSize($percron)->setCurPage(1)->load();
     ini_set('SMTP', Mage::getStoreConfig('system/smtp/host'));
     ini_set('smtp_port', Mage::getStoreConfig('system/smtp/port'));
     /** @var $message Mage_Core_Model_Email_Queue */
     foreach ($collection as $message) {
         if ($message->getId()) {
             $parameters = new Varien_Object($message->getMessageParameters());
             if ($parameters->getReturnPathEmail() !== null) {
                 $mailTransport = new Zend_Mail_Transport_Sendmail("-f" . $parameters->getReturnPathEmail());
                 Zend_Mail::setDefaultTransport($mailTransport);
             }
             $mailer = new Zend_Mail('utf-8');
             foreach ($message->getRecipients() as $recipient) {
                 list($email, $name, $type) = $recipient;
                 switch ($type) {
                     case self::EMAIL_TYPE_BCC:
                         $mailer->addBcc($email, '=?utf-8?B?' . base64_encode($name) . '?=');
                         break;
                     case self::EMAIL_TYPE_TO:
                     case self::EMAIL_TYPE_CC:
                     default:
                         $mailer->addTo($email, '=?utf-8?B?' . base64_encode($name) . '?=');
                         break;
                 }
             }
             if ($parameters->getIsPlain()) {
                 $mailer->setBodyText($message->getMessageBody());
             } else {
                 $mailer->setBodyHTML($message->getMessageBody());
             }
             $mailer->setSubject('=?utf-8?B?' . base64_encode($parameters->getSubject()) . '?=');
             $mailer->setFrom($parameters->getFromEmail(), $parameters->getFromName());
             if ($parameters->getReplyTo() !== null) {
                 $mailer->setReplyTo($parameters->getReplyTo());
             }
             if ($parameters->getReturnTo() !== null) {
                 $mailer->setReturnPath($parameters->getReturnTo());
             }
             foreach (Mage::app()->getStores() as $store) {
                 if ($parameters->getFromEmail() == Mage::getStoreConfig('trans_email/ident_sales/email', $store->getStoreId())) {
                     $storeid = $store->getStoreId();
                 }
             }
             try {
                 $transport = new Varien_Object();
                 Mage::dispatchEvent('aschroder_smtppro_queue_before_send', array('mail' => $mailer, 'transport' => $transport, 'message' => $message, 'store_id' => isset($storeid) ? $storeid : null));
                 if ($transport->getTransport()) {
                     // if set by an observer, use it
                     $mailer->send($transport->getTransport());
                 } else {
                     $mailer->send();
                 }
                 unset($mailer);
                 $message->setProcessedAt(Varien_Date::formatDate(true));
                 $message->save();
                 // loop each email to fire an after send event
                 foreach ($message->getRecipients() as $recipient) {
                     list($email, $name, $type) = $recipient;
                     Mage::dispatchEvent('aschroder_smtppro_after_send', array('to' => $email, 'template' => "queued email", 'subject' => $parameters->getSubject(), 'html' => !$parameters->getIsPlain(), 'email_body' => $message->getMessageBody()));
                 }
             } catch (Exception $e) {
                 unset($mailer);
                 $oldDevMode = Mage::getIsDeveloperMode();
                 Mage::setIsDeveloperMode(true);
                 Mage::logException($e);
                 Mage::setIsDeveloperMode($oldDevMode);
                 return false;
             }
             // after each valid message has been sent - pause if required
             if ($pauseMicros > 0) {
                 $_helper->log('SMTP Pro pausing.');
                 usleep($pauseMicros);
             }
         }
     }
     return $this;
 }
Beispiel #16
0
 /**
  * Send an email to the administator after a mass mailing action.
  *
  * @param array $data Data to build the email content. Report after sending.
  * @return void
  */
 private function _sendMassMailingReport(array $data)
 {
     $fromEmail = $this->_config->massMailing->sender;
     $recipient = $this->_config->massMailing->reportTo;
     $registry = Zend_Registry::getInstance()->set('format', 'email');
     var_dump($data, $fromEmail, $recipient);
     exit;
     $NRTitle = '';
     $sentTo = "Envoyée à ";
     $bodyText = '';
     // send the mail
     $mail = new Zend_Mail();
     $mail->setBodyHtml($bodyText);
     $mail->setFrom($fromEmail, $fromName);
     $mail->setReturnPath($fromEmail);
     $mail->addTo($recipient);
     $mail->setSubject("Rapport d'envoi d' infolettres.");
     $mail->send();
 }
 /**
  * Sets the Return-Path header of the message
  *
  * @param string $email
  * @return Zenc_EmailLogger_Zend_Mail_Logger Provides fluent interface
  *
  * @throws Zend_Mail_Exception if set multiple times
  */
 public function setReturnPath($email)
 {
     $this->getLog()->setReturnPath($email);
     return parent::setReturnPath($email);
 }
Beispiel #18
0
 /**
  * Gets the fully prepared, internal mail object. This can be called directly
  * to allow advanced manipulation before sending
  *
  * @param string $toEmail The email address the email is sent to
  * @param string $toName Name of the person receiving it
  * @param array $headers List of additional headers to send
  * @param string $fromEmail Email address the email should come from; if not specified, uses board default
  * @param string $fromName Name the email should come from; if not specified, uses board default
  * @param string $returnPath The return path of the email (where bounces should go to)
  *
  * @return Zend_Mail|false
  */
 public function getPreparedMailHandler($toEmail, $toName = '', array $headers = array(), $fromEmail = '', $fromName = '', $returnPath = '')
 {
     $contents = $this->prepareMailContents();
     if (!$contents) {
         return false;
     }
     $contents = $this->wrapMailContainer($contents['subject'], $contents['bodyText'], $contents['bodyHtml']);
     $mailObj = new Zend_Mail('utf-8');
     $mailObj->setSubject($contents['subject'])->setBodyText($contents['bodyText'])->addTo($toEmail, $toName);
     if ($contents['bodyHtml'] !== '') {
         $mailObj->setBodyHtml($contents['bodyHtml']);
     }
     $options = XenForo_Application::get('options');
     if (!$fromName) {
         $fromName = $options->emailSenderName ? $options->emailSenderName : $options->boardTitle;
     }
     if ($fromEmail) {
         $mailObj->setFrom($fromEmail, $fromName);
     } else {
         $mailObj->setFrom($options->defaultEmailAddress, $fromName);
     }
     if ($returnPath) {
         $mailObj->setReturnPath($returnPath);
     } else {
         $bounceEmailAddress = $options->bounceEmailAddress;
         if (!$bounceEmailAddress) {
             $bounceEmailAddress = $options->defaultEmailAddress;
         }
         $mailObj->setReturnPath($bounceEmailAddress);
     }
     foreach ($headers as $headerName => $headerValue) {
         $mailObj->addHeader($headerName, $headerValue);
     }
     return $mailObj;
 }
Beispiel #19
0
	function sendEmail($subject, $to_address, $template, $params = null, $to_name = null, $isHtml = false) {
		$useAuth = RivetyCore_Registry::get('smtp_use_auth');

		if (array_key_exists('from_email', $params)) {
			$site_from_email = $params['from_email'];
		} else {
			$site_from_email = RivetyCore_Registry::get('site_from_email');
		}

		// TODO - shouldn't this be from_name instead of from_email ?
		if (array_key_exists('from_name', $params)) {
			$site_from = $params['from_name'];
		} else {
			$site_from = RivetyCore_Registry::get('site_from');
		}

		$smtp = RivetyCore_Registry::get('smtp_server');
		$username = RivetyCore_Registry::get('smtp_username');
		$password = RivetyCore_Registry::get('smtp_password');
		$ssl = RivetyCore_Registry::get('smtp_ssl_type');  //tls
		$smtp_port = RivetyCore_Registry::get('smtp_port');

		$config = array();
		if ($useAuth == 1) {
			$config = array(
				'auth' => 'login',
          		'username' => $username,
          		'password' => $password,
				'ssl' => $ssl,
				'port' => (int)$smtp_port);
		}
		try {
          	$mailTransport = new Zend_Mail_Transport_Smtp($smtp, $config); // defines gmail smtp infrastructure as default for any email message originated by Zend_Mail.
          	Zend_Mail::setDefaultTransport($mailTransport);
			$mail = new Zend_Mail();
			foreach ($params as $key => $value) {
				$this->_smarty->assign($key, $value);
			}
			$message = $this->_smarty->fetch($template);

			if ($isHtml) {
				$mail->setBodyHtml($message);
			} else {
				$mail->setBodyText($message);
			}

			$mail->setFrom($site_from_email, $site_from);
			if (!is_null($to_name) && trim($to_name) != '') {
				$mail->addTo($to_address, $to_name);
			} else {
				$mail->addTo($to_address);
			}
			$mail->setSubject($subject);
			$mail->setReturnPath(RivetyCore_Registry::get('site_from_email'));
			$id_part = substr($site_from_email, strpos('@', $site_from_email));
			$message_id = md5(uniqid()).$id_part;
			//$mail->addHeader('Message-Id', $message_id);

			$mail->send();

		} catch (Exception $e) {
			RivetyCore_Log::report('email: could not send', $e, Zend_Log::ERR);
		}
	}
 protected function sendMail($subject, $address, $from, $body)
 {
     if (null === $this->transport) {
         $this->transport = $this->getTransport();
     }
     // This code prevents memory leak.
     $this->sendCount++;
     if ($this->sendCount > 100) {
         unset($this->transport);
         $this->sendCount = 0;
         $this->transport = $this->getTransport();
     }
     $subject = mb_convert_kana($subject, 'KV');
     $mailer = new Zend_Mail('iso-2022-jp');
     $mailer->setHeaderEncoding(Zend_Mime::ENCODING_BASE64)->setFrom($from)->addTo($address)->setSubject(mb_encode_mimeheader($subject, 'iso-2022-jp'))->setBodyText(mb_convert_encoding($body, 'JIS', 'UTF-8'), 'iso-2022-jp', Zend_Mime::ENCODING_7BIT);
     if ($envelopeFrom = sfConfig::get('op_mail_envelope_from')) {
         $mailer->setReturnPath($envelopeFrom);
     }
     $mailer->send($this->transport);
 }
Beispiel #21
0
 /**
  * set headers in mail to be sent
  * 
  * @param Tinebase_Mail $_mail
  * @param Felamimail_Model_Account $_account
  * @param Felamimail_Model_Message $_message
  * 
  * @todo what has to be set in the 'In-Reply-To' header?
  */
 protected function _setMailHeaders(Zend_Mail $_mail, Felamimail_Model_Account $_account, Felamimail_Model_Message $_message = NULL)
 {
     // add user agent
     $_mail->addHeader('User-Agent', 'Tine 2.0 Email Client (version ' . TINE20_CODENAME . ' - ' . TINE20_PACKAGESTRING . ')');
     $_mail->setReturnPath($_account->email);
     // set organization
     if (isset($_account->organization) && !empty($_account->organization)) {
         $_mail->addHeader('Organization', $_account->organization);
     }
     if ($_message !== NULL) {
         // set in reply to
         if ($_message->flags && $_message->flags == Zend_Mail_Storage::FLAG_ANSWERED && $_message->original_id instanceof Felamimail_Model_Message) {
             $_mail->addHeader('In-Reply-To', $_message->original_id->messageuid);
         }
         //set the header request response
         if ($_message->reading_conf) {
             $_mail->addHeader('Disposition-Notification-To', $_message->from_email);
         }
         // set the Importance header
         if ($_message->importance) {
             $_mail->addHeader('Importance', 'high');
         }
         // add other headers
         if (!empty($_message->headers) && is_array($_message->headers)) {
             if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
                 Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Adding custom headers: ' . print_r($_message->headers, TRUE));
             }
             foreach ($_message->headers as $key => $value) {
                 $_mail->addHeader($key, $value);
             }
         }
     }
 }