public function testEncryptionCanBeSet()
 {
     $transport = TransportFactory::create('smtp', null, null, null, null, 'ssl');
     $this->assertEquals('ssl', $transport->getEncryption());
     $transport = TransportFactory::create('smtp', null, null, null, null, 'tls');
     $this->assertEquals('tls', $transport->getEncryption());
 }
Example #2
0
 public function onKernelRequest(GetResponseEvent $event)
 {
     try {
         $transport = TransportFactory::create($this->modulesSettings->get('Core', 'mailer_type', 'mail'), $this->modulesSettings->get('Core', 'smtp_server'), $this->modulesSettings->get('Core', 'smtp_port', 25), $this->modulesSettings->get('Core', 'smtp_username'), $this->modulesSettings->get('Core', 'smtp_password'), $this->modulesSettings->get('Core', 'smtp_secure_layer'));
         $this->container->set('swiftmailer.mailer.default.transport', $transport);
     } catch (PDOException $e) {
         // we'll just use the mail transport thats pre-configured
     }
 }
Example #3
0
 /**
  * Execute the action
  */
 public function execute()
 {
     parent::execute();
     $fromEmail = \SpoonFilter::getPostValue('mailer_from_email', null, '');
     $fromName = \SpoonFilter::getPostValue('mailer_from_name', null, '');
     $toEmail = \SpoonFilter::getPostValue('mailer_to_email', null, '');
     $toName = \SpoonFilter::getPostValue('mailer_to_name', null, '');
     $replyToEmail = \SpoonFilter::getPostValue('mailer_reply_to_email', null, '');
     $replyToName = \SpoonFilter::getPostValue('mailer_reply_to_name', null, '');
     // init validation
     $errors = array();
     // validate
     if ($fromEmail == '' || !\SpoonFilter::isEmail($fromEmail)) {
         $errors['from'] = BL::err('EmailIsInvalid');
     }
     if ($toEmail == '' || !\SpoonFilter::isEmail($toEmail)) {
         $errors['to'] = BL::err('EmailIsInvalid');
     }
     if ($replyToEmail == '' || !\SpoonFilter::isEmail($replyToEmail)) {
         $errors['reply'] = BL::err('EmailIsInvalid');
     }
     // got errors?
     if (!empty($errors)) {
         $this->output(self::BAD_REQUEST, array('errors' => $errors), 'invalid fields');
     } else {
         $message = \Swift_Message::newInstance('Test')->setFrom(array($fromEmail => $fromName))->setTo(array($toEmail => $toName))->setReplyTo(array($replyToEmail => $replyToName))->setBody(BL::msg('TestMessage'), 'text/plain');
         $transport = \Common\Mailer\TransportFactory::create(\SpoonFilter::getPostValue('mailer_type', array('smtp', 'mail'), 'mail'), \SpoonFilter::getPostValue('smtp_server', null, ''), \SpoonFilter::getPostValue('smtp_port', null, ''), \SpoonFilter::getPostValue('smtp_username', null, ''), \SpoonFilter::getPostValue('smtp_password', null, ''), \SpoonFilter::getPostValue('smtp_secure_layer', null, ''));
         $mailer = \Swift_Mailer::newInstance($transport);
         try {
             if ($mailer->send($message)) {
                 $this->output(self::OK, null, '');
             } else {
                 $this->output(self::ERROR, null, 'unknown');
             }
         } catch (\Exception $e) {
             $this->output(self::ERROR, null, $e->getMessage());
         }
     }
 }