コード例 #1
0
 /**
  * Connect to Mail server
  *
  * @param array $config
  * @return boolean
  */
 public function connect(array $config)
 {
     // Create the Transport
     $this->mailer = new \Swift_SmtpTransport($config['server'], $config['port'], sizeof($config['secure']) > 0 ? $config['secure'] : null);
     $this->mailer->setUsername($config['username']);
     $this->mailer->setPassword($config['password']);
     $this->mailer->start();
     return $this->mailer->isStarted();
 }
コード例 #2
0
 public function execute(Request $request, $function)
 {
     switch ($function) {
         case 'verify-smtp':
             $smtp = new \Swift_SmtpTransport($request->input('smtp-server'), $request->input('smtp-port'), $request->input('smtp-ssl'));
             $smtp->setUsername($request->input('smtp-username'));
             $smtp->setPassword($request->input('smtp-password'));
             $smtp->start();
             $this->ajax_result['errno'] = 0;
             $this->ajax_result['html'] = 'OK';
             $this->ajax_result['smtp'] = $smtp->isStarted();
             //                $this -> ajax_result['errno'] = time() % 2;
             //                $this -> ajax_result['errmsg'] = 'chujnia jakas sie wydazyla';
             //                $this -> ajax_result['html'] = 'chujnia jakas sie wydazyla';
             break;
     }
     echo json_encode($this->ajax_result);
 }
コード例 #3
0
 /**
  * Connect to Mail server
  *
  * @param array $config
  * @throws \RuntimeException
  * @return \Swift_SmtpTransport
  */
 public function connect(array $config)
 {
     // save config
     $this->config = $config;
     try {
         if (!$this->connect) {
             $this->connect = new \Swift_SmtpTransport($config['server'], $config['port'], $config['socket']);
             $this->connect->setUsername($config['username']);
             $this->connect->setPassword($config['password']);
             $this->connect->start();
         }
         if ($this->connect->isStarted() === false) {
             throw new MailException('Mail connection failed! Check configurations');
         }
         return $this;
     } catch (\Exception $e) {
         throw new MailException($e->getMessage());
     }
 }
コード例 #4
0
 /**
  * Tests mail transport settings
  *
  * @param Request $request
  *
  * @return JsonResponse
  */
 protected function testEmailServerConnectionAction(Request $request)
 {
     $dataArray = array('success' => 0, 'error' => '');
     if ($this->factory->getUser()->isAdmin()) {
         $settings = $request->request->all();
         $transport = $settings['transport'];
         switch ($transport) {
             case 'mautic.transport.mandrill':
                 $mailer = new MandrillTransport();
                 break;
             case 'mautic.transport.sendgrid':
                 $mailer = new SendgridTransport();
                 break;
             case 'mautic.transport.amazon':
                 $mailer = new AmazonTransport();
                 break;
             case 'mautic.transport.postmark':
                 $mailer = new PostmarkTransport();
                 break;
             case 'gmail':
                 $mailer = new \Swift_SmtpTransport('smtp.gmail.com', 465, 'ssl');
                 break;
             case 'smtp':
                 $mailer = new \Swift_SmtpTransport($settings['host'], $settings['port'], $settings['encryption']);
                 break;
         }
         if (!empty($mailer)) {
             if (empty($settings['password'])) {
                 $settings['password'] = $this->factory->getParameter('mailer_password');
             }
             $mailer->setUsername($settings['user']);
             $mailer->setPassword($settings['password']);
             $logger = new \Swift_Plugins_Loggers_ArrayLogger();
             $mailer->registerPlugin(new \Swift_Plugins_LoggerPlugin($logger));
             try {
                 $mailer->start();
                 $translator = $this->factory->getTranslator();
                 if ($settings['send_test'] == 'true') {
                     $message = new \Swift_Message($translator->trans('mautic.core.config.form.mailer.transport.test_send.subject'), $translator->trans('mautic.core.config.form.mailer.transport.test_send.body'));
                     $user = $this->factory->getUser();
                     $message->setFrom(array($settings['from_email'] => $settings['from_name']));
                     $message->setTo(array($user->getEmail() => $user->getFirstName() . ' ' . $user->getLastName()));
                     $mailer->send($message);
                 }
                 $dataArray['success'] = 1;
                 $dataArray['message'] = $translator->trans('mautic.core.success');
             } catch (\Exception $e) {
                 $dataArray['message'] = $e->getMessage() . '<br />' . $logger->dump();
             }
         }
     }
     return $this->sendJsonResponse($dataArray);
 }