/** * Test case method */ public function testMailTransport() { $mailTransport = Shopware()->MailTransport(); $mail = new Enlight_Components_Mail(); $mail->setBodyText('Test Hallo'); $mail->addTo('*****@*****.**'); $mail = $mail->send($mailTransport); $this->assertInstanceOf('Zend_Mail', $mail); }
/** * Adds an error to the list of errors. * * @param PHPUnit_Framework_Test $test * @param Exception $e * @param float $time */ public function addError(PHPUnit_Framework_Test $test, Exception $e, $time) { $message = "\n" . $e->getMessage(); if ($e instanceof PHPUnit_Framework_ExpectationFailedException) { /** @var $e PHPUnit_Framework_ExpectationFailedException */ //$message .= "\n" . $e->getComparisonFailure()->toString(); } $name = $test->getName(false); $mail = new Enlight_Components_Mail(); $mail->addTo($this->mailRecipients); $mail->setSubject('PHPUnit test "' . $name . '" failed.'); $mail->setBodyText($message); if($test instanceof Enlight_Components_Test_Selenium_TestCase && $e instanceof PHPUnit_Framework_ExpectationFailedException && $screenshot = $test->getFullScreenshot()) { $filename = basename($test->getFullScreenshotUrl()); /** @var $test Enlight_Components_Test_Selenium_TestCase */ $mail->createAttachment( $screenshot, Zend_Mime::TYPE_OCTETSTREAM, Zend_Mime::DISPOSITION_ATTACHMENT, Zend_Mime::ENCODING_BASE64, $filename ); } $mail->send($this->mailTransport); }
/** * Loads values from MailModel into Mail * * @param \Enlight_Components_Mail $mail * @param \Shopware\Models\Mail\Mail $mailModel * @param array $overrideConfig * @return \Enlight_Components_Mail * @throws \Enlight_Exception */ public function loadValues(\Enlight_Components_Mail $mail, \Shopware\Models\Mail\Mail $mailModel, $overrideConfig = array()) { $stringCompiler = $this->getStringCompiler(); $subject = $stringCompiler->compileString($mailModel->getSubject()); if (!empty($subject)) { $mail->setSubject($subject); } if (!empty($overrideConfig["fromMail"])) { $fromMail = $overrideConfig["fromMail"]; } else { $fromMail = $stringCompiler->compileString($mailModel->getFromMail()); } if (!empty($overrideConfig["fromName"])) { $fromName = $overrideConfig["fromName"]; } else { $fromName = $stringCompiler->compileString($mailModel->getFromName()); } if (!empty($fromMail) && !empty($fromName)) { $mail->setFrom($fromMail, $fromName); } elseif (!empty($fromMail)) { $mail->setFrom($fromMail); } $bodyText = $stringCompiler->compileString($mailModel->getContent()); $mail->setBodyText($bodyText); if ($mailModel->isHtml()) { $mail->setBodyHtml($stringCompiler->compileString($mailModel->getContentHtml())); } /** @var $attachment \Shopware\Models\Mail\Attachment */ foreach ($mailModel->getAttachments() as $attachment) { if ($attachment->getShopId() !== null && ($this->getShop() === null || $attachment->getShopId() != $this->getShop()->getId())) { continue; } $mediaService = Shopware()->Container()->get('shopware_media.media_service'); if (!$mediaService->has($attachment->getPath())) { Shopware()->Container()->get('corelogger')->error('Could not load file: ' . $attachment->getPath()); } else { $fileAttachment = $mail->createAttachment($mediaService->read($attachment->getPath())); $fileAttachment->filename = $attachment->getFileName(); } } return $mail; }
/** * Loads values from MailModel into Mail * * @param \Enlight_Components_Mail $mail * @param \Shopware\Models\Mail\Mail $mailModel * @param array $overrideConfig * @return \Enlight_Components_Mail * @throws \Enlight_Exception */ public function loadValues(\Enlight_Components_Mail $mail, \Shopware\Models\Mail\Mail $mailModel, $overrideConfig = array()) { $stringCompiler = $this->getStringCompiler(); $subject = $stringCompiler->compileString($mailModel->getSubject()); if (!empty($subject)) { $mail->setSubject($subject); } if (!empty($overrideConfig["fromMail"])) { $fromMail = $overrideConfig["fromMail"]; } else { $fromMail = $stringCompiler->compileString($mailModel->getFromMail()); } if (!empty($overrideConfig["fromName"])) { $fromName = $overrideConfig["fromName"]; } else { $fromName = $stringCompiler->compileString($mailModel->getFromName()); } if (!empty($fromMail) && !empty($fromName)) { $mail->setFrom($fromMail, $fromName); } elseif (!empty($fromMail)) { $mail->setFrom($fromMail); } $bodyText = $stringCompiler->compileString($mailModel->getContent()); $mail->setBodyText($bodyText); if ($mailModel->isHtml()) { $mail->setBodyHtml($stringCompiler->compileString($mailModel->getContentHtml())); } /** @var $attachment \Shopware\Models\Mail\Attachment */ foreach ($mailModel->getAttachments() as $attachment) { if ($attachment->getShopId() !== null && ($this->getShop() === null || $attachment->getShopId() != $this->getShop()->getId())) { continue; } if (false === ($fileHandle = fopen($attachment->getPath(), 'r'))) { throw new \Enlight_Exception('Could not load file: ' . $attachment->getPath()); } $fileAttachment = $mail->createAttachment($fileHandle); $fileAttachment->filename = $attachment->getFileName(); } return $mail; }
/** * Send status mail * * @param Enlight_Components_Mail $mail * @return Enlight_Components_Mail */ public function sendStatusMail(Enlight_Components_Mail $mail) { $this->eventManager->notify('Shopware_Controllers_Backend_OrderState_Send_BeforeSend', array('subject' => Shopware()->Front(), 'mail' => $mail)); if (!empty($this->config->OrderStateMailAck)) { $mail->addBcc($this->config->OrderStateMailAck); } return $mail->send(); }
/** * @return BufferHandler */ public function createMailHandler() { $mailer = new \Enlight_Components_Mail(); $mailer->addTo(Shopware()->Config()->Mail); $mailer->setSubject('Error in shop "' . Shopware()->Config()->Shopname . '".'); $mailHandler = new EnlightMailHandler($mailer, \Monolog\Logger::WARNING); $mailHandler->pushProcessor(new ShopwareEnvironmentProcessor()); $mailHandler->setFormatter(new HtmlFormatter()); $bufferedHandler = new BufferHandler($mailHandler); return $bufferedHandler; }
/** * Sets the given Zend_Log object into the internal log property. * If no log given, a new instance with the internal configuration will be created. * @param Enlight_Components_Log|Zend_Log $log */ public function setResource(Zend_Log $log = null) { if ($log === null) { $log = new Enlight_Components_Log(); $log->setEventItem('date', Zend_Date::now()); $log->addWriter(new Zend_Log_Writer_Null()); $config = $this->Config(); if(!empty($config->logDb)) { $writer = Zend_Log_Writer_Db::factory(array( 'db' => Shopware()->Db(), 'table' => 's_core_log', 'columnmap' => array( 'type' => 'priority', 'key' => 'priorityName', 'text' => 'message', 'date' => 'date', 'ip_address' => 'remote_address', 'user_agent' => 'user_agent', ) )); $writer->addFilter(Enlight_Components_Log::WARN); $log->addWriter($writer); } if(!empty($config->logMail)) { $mail = new Enlight_Components_Mail(); $mail->addTo(Shopware()->Config()->Mail); $writer = new Zend_Log_Writer_Mail($mail); $writer->setSubjectPrependText('Fehler im Shop "'.Shopware()->Config()->Shopname.'" aufgetreten!'); $writer->addFilter(Enlight_Components_Log::WARN); $log->addWriter($writer); } } $this->log = $log; }
/** * Init mail transport * * @return Zend_Mail_Transport_Abstract */ protected function initMailTransport() { $options = Shopware()->getOption('mail') ? Shopware()->getOption('mail') : array(); $config = $this->getResource('Config'); if (!isset($options['type']) && !empty($config->MailerMailer) && $config->MailerMailer!='mail') { $options['type'] = $config->MailerMailer; } if (empty($options['type'])) { $options['type'] = 'sendmail'; } if ($options['type'] == 'smtp') { if (!isset($options['username']) && !empty($config->MailerUsername)) { if (!empty($config->MailerAuth)) { $options['auth'] = $config->MailerAuth; } elseif (empty($options['auth'])) { $options['auth'] = 'login'; } $options['username'] = $config->MailerUsername; $options['password'] = $config->MailerPassword; } if (!isset($options['ssl']) && !empty($config->MailerSMTPSecure)) { $options['ssl'] = $config->MailerSMTPSecure; } if (!isset($options['port']) && !empty($config->MailerPort)) { $options['port'] = $config->MailerPort; } if (!isset($options['name']) && !empty($config->MailerHostname)) { $options['name'] = $config->MailerHostname; } if (!isset($options['host']) && !empty($config->MailerHost)) { $options['host'] = $config->MailerHost; } } if (!Shopware()->Loader()->loadClass($options['type'])) { $transportName = ucfirst(strtolower($options['type'])); $transportName = 'Zend_Mail_Transport_'.$transportName; } else { $transportName = $options['type']; } unset($options['type'], $options['charset']); if ($transportName=='Zend_Mail_Transport_Smtp') { $transport = Enlight_Class::Instance($transportName, array($options['host'], $options)); } elseif (!empty($options)) { $transport = Enlight_Class::Instance($transportName, array($options)); } else { $transport = Enlight_Class::Instance($transportName); } Enlight_Components_Mail::setDefaultTransport($transport); if (!isset($options['from']) && !empty($config->Mail)) { $options['from'] = array('email'=>$config->Mail, 'name'=>$config->Shopname); } if (!empty($options['from']['email'])) { Enlight_Components_Mail::setDefaultFrom( $options['from']['email'], !empty($options['from']['name']) ? $options['from']['name'] : null ); } if (!empty($options['replyTo']['email'])) { Enlight_Components_Mail::setDefaultReplyTo( $options['replyTo']['email'], !empty($options['replyTo']['name']) ? $options['replyTo']['name'] : null ); } return $transport; }
/** * @param \Enlight_Loader $loader * @param \Shopware_Components_Config $config * @param array $options * @return \Enlight_Class|\Zend_Mail_Transport_Abstract */ public function factory(\Enlight_Loader $loader, \Shopware_Components_Config $config, array $options) { if (!isset($options['type']) && !empty($config->MailerMailer) && $config->MailerMailer != 'mail') { $options['type'] = $config->MailerMailer; } if (empty($options['type'])) { $options['type'] = 'sendmail'; } if ($options['type'] == 'smtp') { if (!isset($options['username']) && !empty($config->MailerUsername)) { if (!empty($config->MailerAuth)) { $options['auth'] = $config->MailerAuth; } elseif (empty($options['auth'])) { $options['auth'] = 'login'; } $options['username'] = $config->MailerUsername; $options['password'] = $config->MailerPassword; } if (!isset($options['ssl']) && !empty($config->MailerSMTPSecure)) { $options['ssl'] = $config->MailerSMTPSecure; } if (!isset($options['port']) && !empty($config->MailerPort)) { $options['port'] = $config->MailerPort; } if (!isset($options['name']) && !empty($config->MailerHostname)) { $options['name'] = $config->MailerHostname; } if (!isset($options['host']) && !empty($config->MailerHost)) { $options['host'] = $config->MailerHost; } } if (!$loader->loadClass($options['type'])) { $transportName = ucfirst(strtolower($options['type'])); $transportName = 'Zend_Mail_Transport_' . $transportName; } else { $transportName = $options['type']; } unset($options['type'], $options['charset']); if ($transportName == 'Zend_Mail_Transport_Smtp') { $transport = \Enlight_Class::Instance($transportName, array($options['host'], $options)); } elseif (!empty($options)) { $transport = \Enlight_Class::Instance($transportName, array($options)); } else { $transport = \Enlight_Class::Instance($transportName); } /** @var $transport \Zend_Mail_Transport_Abstract */ \Enlight_Components_Mail::setDefaultTransport($transport); if (!isset($options['from']) && !empty($config->Mail)) { $options['from'] = array('email' => $config->Mail, 'name' => $config->Shopname); } if (!empty($options['from']['email'])) { \Enlight_Components_Mail::setDefaultFrom($options['from']['email'], !empty($options['from']['name']) ? $options['from']['name'] : null); } if (!empty($options['replyTo']['email'])) { \Enlight_Components_Mail::setDefaultReplyTo($options['replyTo']['email'], !empty($options['replyTo']['name']) ? $options['replyTo']['name'] : null); } return $transport; }