Exemplo n.º 1
0
 /**
  * Constructor for ticketing service adapter
  *
  * @param array $settings
  */
 public function __construct(array $settings)
 {
     $this->transport = TransportFactory::create($settings['transport']);
     $this->to = $settings['to'];
     $this->from = isset($settings['from']) ? $settings['from'] : null;
     $this->subjectPrefix = isset($settings['subject_prefix']) ? $settings['subject_prefix'] : null;
 }
Exemplo n.º 2
0
 public function createService(ServiceLocatorInterface $services)
 {
     $service = new EmailService();
     $config = $services->get('Config');
     $transport = Factory::create($config['email']);
     $service->setTransport($transport);
     return $service;
 }
Exemplo n.º 3
0
 /**
  * @param EmailOptions $options
  * @return EmailInterface
  */
 public function createEmail(EmailOptions $options)
 {
     $transport = Factory::create($options->getTransport());
     $email = new Email($transport);
     $from = $options->getFrom();
     if (is_array($from)) {
         $from = new Address($from[0], $from[1]);
     }
     $email->setFrom($from);
     return $email;
 }
Exemplo n.º 4
0
 public function __construct(array $mailConfig, RendererInterface $renderer)
 {
     if (!array_key_exists('mail', $mailConfig)) {
         throw new \Exception('mail-config is incomplete!');
     }
     $this->mailAddress = $mailConfig['mail']['senderMail'];
     $this->senderName = $mailConfig['mail']['senderName'];
     if (array_key_exists('transport', $mailConfig['mail']) && is_array($mailConfig['mail']['transport'])) {
         $this->transport = Factory::create($mailConfig['mail']['transport']);
     } else {
         $this->transport = Factory::create([]);
     }
     $this->renderer = $renderer;
 }
 public function createService(ServiceLocatorInterface $serviceLocator)
 {
     /** @var TransportOptions $options */
     $config = $serviceLocator->get('config');
     $options = $config['goaliomailservice'];
     // Backwards compatibility with old config files
     if (isset($options['transport_class']) && !isset($options['type'])) {
         $options['type'] = $options['transport_class'];
     }
     if (isset($options['transport_options']) && !isset($options['options'])) {
         $options['options'] = $options['transport_options'];
     }
     return \Zend\Mail\Transport\Factory::create($options);
 }
Exemplo n.º 6
0
 /**
  * Create the mailer service.
  * 
  * @param ServiceLocatorInterface $serviceLocator
  * @return Mialer
  */
 public function createService(ServiceLocatorInterface $serviceLocator)
 {
     $config = $serviceLocator->get('Config');
     if (!isset($config['mail']['transport'])) {
         throw new Exception\ConfigException('Missing mail transport configuration');
     }
     $transport = TransportFactory::create($config['mail']['transport']);
     $defaultOptions = [];
     if (isset($config['mail']['default_message_options'])) {
         $defaultOptions = $config['mail']['default_message_options'];
     }
     if (!isset($defaultOptions['administrator_email'])) {
         $settings = $serviceLocator->get('Omeka\\Settings');
         $defaultOptions['from'] = $settings->get('administrator_email');
     }
     return new Mailer($transport, $defaultOptions);
 }
Exemplo n.º 7
0
 /**
  *
  */
 public function testCanCreateFileTransportWithOptions()
 {
     $transport = Factory::create(array('type' => 'file', 'options' => array('path' => __DIR__)));
     $this->assertEquals($transport->getOptions()->getPath(), __DIR__);
 }
Exemplo n.º 8
0
 /**
  * Constructor
  *
  * @param  MailMessage|array|Traversable $mail
  * @param  Transport\TransportInterface $transport Optional
  * @throws Exception\InvalidArgumentException
  */
 public function __construct($mail, Transport\TransportInterface $transport = null)
 {
     if ($mail instanceof Traversable) {
         $mail = iterator_to_array($mail);
     }
     if (is_array($mail)) {
         parent::__construct($mail);
         if (isset($mail['subject_prepend_text'])) {
             $this->setSubjectPrependText($mail['subject_prepend_text']);
         }
         $transport = isset($mail['transport']) ? $mail['transport'] : null;
         $mail = isset($mail['mail']) ? $mail['mail'] : null;
         if (is_array($mail)) {
             $mail = MailMessageFactory::getInstance($mail);
         }
         if (is_array($transport)) {
             $transport = Transport\Factory::create($transport);
         }
     }
     // Ensure we have a valid mail message
     if (!$mail instanceof MailMessage) {
         throw new Exception\InvalidArgumentException(sprintf('Mail parameter of type %s is invalid; must be of type Zend\\Mail\\Message', is_object($mail) ? get_class($mail) : gettype($mail)));
     }
     $this->mail = $mail;
     // Ensure we have a valid mail transport
     if (null === $transport) {
         $transport = new Transport\Sendmail();
     }
     if (!$transport instanceof Transport\TransportInterface) {
         throw new Exception\InvalidArgumentException(sprintf('Transport parameter of type %s is invalid; must be of type Zend\\Mail\\Transport\\TransportInterface', is_object($transport) ? get_class($transport) : gettype($transport)));
     }
     $this->setTransport($transport);
     if ($this->formatter === null) {
         $this->formatter = new SimpleFormatter();
     }
 }
Exemplo n.º 9
0
 public function sendAction()
 {
     $output = [];
     // So hacky, but it works
     exec('ps aux | grep \'[p]\'hp | grep \'[s\']end-emails', $output);
     if (count($output) > 1) {
         print "Already running, exitting\n";
         return;
     }
     print "\n" . self::COLOUR_BOLDWHITE . 'E-mail processor' . self::COLOUR_RESET . "\n";
     print self::COLOUR_BOLDBLUE . '================' . self::COLOUR_RESET . "\n\n";
     $request = $this->getRequest();
     if (!$request instanceof ConsoleRequest) {
         throw new RuntimeException('You can only use this action from a console!');
     }
     try {
         $serviceLocator = $this->getServiceLocator();
         $config = $serviceLocator->get('Config');
         $transport = TransportFactory::create($config['vinari-core']['email']['transport']);
         $objectManager = $this->getServiceLocator()->get('Doctrine\\ORM\\EntityManager');
         $emailRepository = $objectManager->getRepository($config['vinari-core']['entity']);
         // Check flags
         $limit = (int) ($request->getParam('limit') || $request->getParam('l'));
         $dryRun = (bool) $request->getParam('dry-run');
         print self::COLOUR_YELLOW . 'Fetching e-mails to send… ' . self::COLOUR_RESET;
         $emails = $emailRepository->findBy(['status' => 'not-sent']);
         print self::COLOUR_BOLDGREEN . 'Done.' . self::COLOUR_RESET . "\n";
         if (!count($emails)) {
             print self::COLOUR_YELLOW . 'Nothing to send; exiting.' . self::COLOUR_RESET . "\n\n";
         } else {
             print self::COLOUR_YELLOW . 'Found ' . count($emails) . ' e-mails to send.' . self::COLOUR_RESET . "\n";
             print self::COLOUR_YELLOW . 'Sending e-mails…' . self::COLOUR_RESET . "\n";
             $i = 0;
             foreach ($emails as $email) {
                 print self::COLOUR_YELLOW . '    ' . $email->getToName() . ' <' . $email->getToAddress() . '>… ' . self::COLOUR_RESET;
                 $mail = new Message();
                 $mail->addTo($email->getToAddresses(), $email->getToName());
                 $mail->addFrom($email->getFromAddress(), $email->getFromName());
                 $mail->setEncoding('UTF-8');
                 $mail->setBody($email->getTextContent());
                 $mail->setSubject($email->getSubject());
                 try {
                     if (!$dryRun) {
                         $transport->send($mail);
                     }
                     $email->setStatus('sent');
                     print self::COLOUR_BOLDGREEN . 'Done.' . self::COLOUR_RESET . "\n";
                 } catch (\Exception $ee) {
                     $error = $this->logError($ee->getCode() ? $ee->getCode() : 500, $ee->getMessage(), $ee->getFile(), $ee->getLine(), $ee->getTrace());
                     $email->setError($error);
                     $email->setStatus('failed');
                     print self::COLOUR_BOLDRED . 'Failed: ' . self::COLOUR_WHITE . $ee->getMessage() . self::COLOUR_RESET . "\n";
                 }
                 if (!$dryRun) {
                     $objectManager->persist($email);
                     $objectManager->flush();
                 }
                 if ($limit > 0 && ++$i >= $limit) {
                     break;
                 }
             }
         }
         print self::COLOUR_BOLDGREEN . 'Done.' . self::COLOUR_RESET . "\n\n";
     } catch (\Exception $e) {
         print self::COLOUR_BOLDRED . 'Failed: ' . self::COLOUR_WHITE . $e->getMessage() . self::COLOUR_RESET . "\n\n";
     }
 }
Exemplo n.º 10
0
 /**
  * Create service
  *
  * @param ServiceLocatorInterface $serviceLocator
  * @return mixed
  */
 public function createService(ServiceLocatorInterface $serviceLocator)
 {
     $config = $serviceLocator->get('config')['toolbox_mail'];
     $transport = \Zend\Mail\Transport\Factory::create($config['transport']);
     return new MailService($serviceLocator->get('viewrenderer'), $serviceLocator->get(ModuleOptions::class), $transport);
 }
Exemplo n.º 11
0
 public function createService(ServiceLocatorInterface $serviceLocator)
 {
     /* @var $options SiteEmailOptions */
     $options = $serviceLocator->get(SiteEmailOptions::class);
     return \Zend\Mail\Transport\Factory::create($options->getTransportConfig());
 }