Esempio n. 1
1
 public function getErrors(Config $cfg)
 {
     $i18n = Localization::getTranslator();
     $walletSettings = [];
     $emailSettings = [];
     $providerClass = '';
     try {
         $provider = $cfg->getWalletProvider();
         $providerClass = get_class($provider);
         $provider->verifyOwnership();
     } catch (Exception $e) {
         if (strpos($providerClass, 'CoinbaseWallet') !== false) {
             $walletSettings[] = ['id' => '#wallet-coinbaseApiKey-error', 'error' => $e->getMessage()];
         } else {
             $walletSettings[] = ['id' => '#wallet-id-error', 'error' => $e->getMessage()];
         }
     }
     try {
         $t = new Swift_SmtpTransport('smtp.gmail.com', 465, 'ssl');
         $t->setUsername($cfg->getEmailUsername())->setPassword($cfg->getEmailPassword())->start();
     } catch (Exception $e) {
         $emailSettings[] = ['id' => '#email-username-error', 'error' => $e->getMessage()];
     }
     $errors = [];
     if (!empty($pricingSettings)) {
         $errors['#pricing-settings'] = self::getPricingErrorsFromConfig($cfg);
     }
     if (!empty($walletSettings)) {
         $errors['#wallet-settings'] = $walletSettings;
     }
     if (!empty($emailSettings)) {
         $errors['#email-settings'] = $emailSettings;
     }
     return $errors;
 }
 /**
  * Initialize the component
  */
 public function init()
 {
     $this->initAutoloader($this->swiftBasePath);
     $this->transport = Swift_SmtpTransport::newInstance($this->host, $this->port, $this->security);
     $this->transport->setUsername($this->username)->setPassword($this->password);
     parent::init();
 }
 /**
  * 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();
 }
Esempio n. 4
0
 public function send()
 {
     $smtpTransport = new \Swift_SmtpTransport($this->spoolMailerParam('host'), $this->spoolMailerParam('port'));
     $smtpTransport->setUsername($this->spoolMailerParam('username'));
     $smtpTransport->setPassword($this->spoolMailerParam('password'));
     $this->spool->flushQueue($smtpTransport);
 }
 public function testReport()
 {
     //  Arrange.
     $transport = new \Swift_SmtpTransport();
     $transport->setHost('mailtrap.io');
     $transport->setPort(2525);
     $transport->setUsername(getenv('MAILTRAP_USERNAME'));
     $transport->setPassword(getenv('MAILTRAP_PASSWORD'));
     $mailer = new Swift_Mailer($transport);
     $message = new Swift_Message();
     $message->addTo('*****@*****.**');
     $message->setFrom('*****@*****.**');
     $body = new Body(new VarCloner(), new CliDumper());
     $compiler = new Compiler(new CommonMarkConverter(), new CssToInlineStyles());
     $email = new Email($mailer, $message, $body, $compiler);
     $exception = new DomainException('Testing a domain exception');
     $extra = ['only' => 'testing12321'];
     // Act.
     $email->report($exception, $extra);
     // Assert.
     $message = $this->mailtrap->get('inboxes/' . getenv('MAILTRAP_INBOX') . '/messages')->json()[0];
     $this->assertSame('Exception: Testing a domain exception', $message['subject']);
     $this->assertContains('$email->report($exception, $extra);', $message['text_body']);
     $this->assertContains("exception 'DomainException' with message 'Testing a domain exception'", $message['text_body']);
     $this->assertContains('{main}', $message['text_body']);
     $this->assertContains('"only" => "testing12321"', $message['text_body']);
     $this->assertContains('_SERVER', $message['text_body']);
 }
Esempio n. 6
0
 protected function init($config = array())
 {
     $transport = new \Swift_SmtpTransport($this->smtpHost, $this->smtpPort, $this->smtpSecure);
     $transport->setUsername($this->smtpUser);
     $transport->setPassword($this->smtpPassword);
     $this->mailer = new \Swift_Mailer($transport);
     return parent::init();
 }
Esempio n. 7
0
 /**
  * Changes mailer configuration on runtime
  *
  * @param MailerConfiguration $mailerConfiguration
  *
  * @return \Swift_Mailer
  */
 protected function createMailer(MailerConfiguration $mailerConfiguration)
 {
     $transport = new \Swift_SmtpTransport();
     $transport->setHost($mailerConfiguration->getHost());
     $transport->setPort($mailerConfiguration->getPort());
     $transport->setUsername($mailerConfiguration->getUser());
     $transport->setPassword($mailerConfiguration->getPass());
     return \Swift_Mailer::newInstance($transport);
 }
Esempio n. 8
0
 /**
  * Mailer constructor.
  * @param $configuration
  */
 public function __construct($configuration)
 {
     $transport = new \Swift_SmtpTransport($configuration["host"], $configuration["port"]);
     $transport->setUsername($configuration["username"]);
     $transport->setPassword($configuration["password"]);
     $transport->setAuthMode($configuration["auth_mode"]);
     $transport->setEncryption($configuration["encryption"]);
     $this->mailer = new \Swift_Mailer($transport);
     $this->debugMail = isset($configuration["debug_email"]) ? $configuration["debug_email"] : null;
 }
Esempio n. 9
0
 function send_breakin_alert($email, $password)
 {
     $transporter = new Swift_SmtpTransport('smtp.gmail.com', 465, 'ssl');
     $transporter->setUsername('');
     $transporter->setPassword('');
     $message = new Swift_Message($transporter);
     $message->setTo(array($email => $email));
     $message->setSubject("Note to Myself - Break-in Attempt");
     $message->addPart("Your password has been reset after 3 failed log-in attempts.</br>Your new password is <strong>{$password}</strong>", 'text/html');
     $message->setFrom("", "");
     $mailer = new Swift_Mailer($transporter);
     $mailer->send($message);
 }
Esempio n. 10
0
 /**
  * @param $from
  * @return \Swift_Mailer
  */
 protected function __getSwiftMailer($from)
 {
     if (!isset($this->swiftMailers[$hash = md5(json_encode($from))])) {
         $transport = new \Swift_SmtpTransport(isset($from['smtpHost']) ? $from['smtpHost'] : '127.0.0.1', isset($from['smtpPort']) ? $from['smtpPort'] : 25, isset($from['smtpSecure']) ? $from['smtpSecure'] : false);
         if (isset($from['smtpUser'])) {
             $transport->setUsername($from['smtpUser']);
         }
         if (isset($from['smtpPassword'])) {
             $transport->setPassword($from['smtpPassword']);
         }
         $this->swiftMailers[$hash] = new \Swift_Mailer($transport);
     }
     return $this->swiftMailers[$hash];
 }
Esempio n. 11
0
 /**
  * @param string|null $host
  * @param int|null    $port
  * @param array|null  $headers
  * @param string|null $username
  * @param string|null $password
  * @param string|null $security
  * @return CM_Mail_Mailer
  */
 public function createSmtpMailer($host = null, $port = null, array $headers = null, $username = null, $password = null, $security = null)
 {
     $host = null !== $host ? (string) $host : 'localhost';
     $port = null !== $port ? (int) $port : 25;
     $headers = null !== $headers ? (array) $headers : [];
     $security = null !== $security ? (string) $security : null;
     $transport = new Swift_SmtpTransport($host, $port, $security);
     if (null !== $username) {
         $transport->setUsername((string) $username);
     }
     if (null !== $password) {
         $transport->setPassword((string) $password);
     }
     return new CM_Mail_Mailer($transport, $headers);
 }
Esempio n. 12
0
 static function startUp(KernelInterface $kernel, ModuleInfo $moduleInfo)
 {
     $kernel->onRegisterServices(function (InjectorInterface $injector) {
         $injector->delegate(Swift_Mailer::class, function () use($injector) {
             $transport = new \Swift_SmtpTransport(env('EMAIL_SMTP_HOST', 'localhost'), env('EMAIL_SMTP_PORT', 25));
             if (env('EMAIL_SMTP_AUTH')) {
                 $transport->setUsername(env('EMAIL_SMTP_USERNAME'))->setPassword(env('EMAIL_SMTP_PASSWORD'));
             }
             $mailer = new Swift_Mailer($transport);
             $logger = new Swift_Plugins_Loggers_ArrayLogger(self::MAX_LOG_SIZE);
             $mailer->registerPlugin(new Swift_Plugins_LoggerPlugin($logger));
             // Create run-time custom property to allow easy access to the logger.
             $mailer->logger = $logger;
             return $mailer;
         });
     });
 }
Esempio n. 13
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);
 }
Esempio n. 14
0
 public function __construct(array $options = array())
 {
     $swiftTransort = new \Swift_SmtpTransport();
     $swiftTransort->setHost($options['smtp']);
     $swiftTransort->setPort($options['port']);
     if (isset($options['encryption'])) {
         $swiftTransort->setEncryption($options['encryption']);
     }
     if (isset($options['username'])) {
         $swiftTransort->setUsername($options['username']);
     }
     if (isset($options['password'])) {
         $swiftTransort->setPassword($options['password']);
     }
     if (isset($options['auth_mode'])) {
         $swiftTransort->setAuthMode($options['auth_mode']);
     }
     $this->_mailer = new \Swift_Mailer($swiftTransort);
 }
Esempio n. 15
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());
     }
 }
Esempio n. 16
0
 public function send()
 {
     $this->instance->setTo($this->to);
     $this->instance->setCc($this->cc);
     $this->instance->setBcc($this->bcc);
     $this->instance->setFrom($this->from);
     $this->instance->setBody($this->body, 'text/plain');
     if ($this->html !== NULL) {
         $this->instance->addPart($this->html, 'text/html');
     }
     if ($this->smtp_tls) {
         $transport = new \Swift_SmtpTransport($this->smtp_host, $this->smtp_port, 'tls');
     } elseif ($this->smtp_ssl) {
         $transport = new \Swift_SmtpTransport($this->smtp_host, $this->smtp_port, 'ssl');
     } else {
         $transport = new \Swift_SmtpTransport($this->smtp_host, $this->smtp_port);
     }
     $transport->setUsername($this->smtp_user)->setPassword($this->smtp_pass);
     $mailer = new \Swift_Mailer($transport);
     $mailer->send($this->instance);
 }
Esempio n. 17
0
 /**
  * {@inheritdoc}
  */
 public function createHandler($config)
 {
     if (!isset($config['host'])) {
         throw new AcmeCliException('The SMTP host (key "host") is required in the email monitoring alert handler.');
     }
     if (!isset($config['to'])) {
         throw new AcmeCliException('The mail recipient (key "to") is required in the email monitoring alert handler.');
     }
     $config = array_merge(self::$defaults, $config);
     $transport = new \Swift_SmtpTransport($config['host'], $config['port'], $config['encryption']);
     if ($config['username']) {
         $transport->setUsername($config['username']);
     }
     if ($config['password']) {
         $transport->setPassword($config['password']);
     }
     $message = new \Swift_Message($config['subject']);
     $message->setFrom($config['from']);
     $handler = new SwiftMailerHandler(new \Swift_Mailer($transport), $message);
     return new FingersCrossedHandler($handler, $config['level']);
 }
Esempio n. 18
0
 /**
  * @return \Swift_Mailer
  * @throws \Exception
  */
 public function getSwiftMailer()
 {
     if ($this->configuration['transport'] !== 'smtp') {
         throw new \Exception('The MailService only supports SMTP at the moment', 1456822674);
     }
     if ($this->configuration['smtp_encryption'] === 'none') {
         $this->configuration['smtp_encryption'] = NULL;
     }
     if (!$this->configuration['smtp_port']) {
         if ($this->configuration['smtp_encryption'] === 'ssl') {
             $this->configuration['smtp_port'] = '465';
         } else {
             $this->configuration['smtp_port'] = '587';
         }
     }
     $transport = new \Swift_SmtpTransport($this->configuration['smtp_host'], $this->configuration['smtp_port']);
     if (!empty($this->configuration['smtp_username'])) {
         $transport->setUsername($this->configuration['smtp_username']);
     }
     if (!empty($this->configuration['smtp_password'])) {
         $transport->setPassword($this->configuration['smtp_password']);
     }
     return \Swift_Mailer::newInstance($transport);
 }
$dbConfiguration = new DbConfiguration($parameters);
// the connection configuration
$dbParams = array('driver' => $dbConfiguration->getDriver(), 'user' => $dbConfiguration->getUsername(), 'password' => $dbConfiguration->getPassword(), 'dbname' => $dbConfiguration->getDatabaseName(), 'host' => $dbConfiguration->getHost(), 'port' => $dbConfiguration->getPort());
$eventManager = new Doctrine\Common\EventManager();
$timestampableListener = new Gedmo\Timestampable\TimestampableListener();
$eventManager->addEventSubscriber($timestampableListener);
AnnotationRegistry::registerLoader(array($loader, 'loadClass'));
$annotationMetadataConfiguration = Setup::createAnnotationMetadataConfiguration($paths, $debug, null, new ArrayCache(), false);
$entityManager = EntityManager::create($dbParams, $annotationMetadataConfiguration, $eventManager);
$helperSet = ConsoleRunner::createHelperSet($entityManager);
$logger = new Logger("hipay");
$logFilePath = $parameters['log.file.path'] ?: DEFAULT_LOG_PATH;
$logger->pushHandler(new StreamHandler($logFilePath));
$swiftTransport = new Swift_SmtpTransport($parameters['mail.host'], $parameters['mail.port'], $parameters['mail.security']);
if (isset($parameters['mail.username']) && isset($parameters['mail.password'])) {
    $swiftTransport->setUsername($parameters['mail.username']);
    $swiftTransport->setPassword($parameters['mail.password']);
}
$mailer = new Swift_Mailer($swiftTransport);
$messageTemplate = new Swift_Message();
$messageTemplate->setSubject($parameters['mail.subject']);
$messageTemplate->setTo($parameters['mail.to']);
$messageTemplate->setFrom($parameters['mail.from']);
$messageTemplate->setCharset('utf-8');
$logger->pushHandler(new SwiftMailerHandler($mailer, $messageTemplate, Logger::CRITICAL));
$logger->pushProcessor(new PsrLogMessageProcessor());
/** @var ValidatorInterface $validator */
$validator = Validation::createValidatorBuilder()->enableAnnotationMapping()->getValidator();
$miraklConfiguration = new MiraklConfiguration($parameters);
$hipayConfiguration = new HiPayConfiguration($parameters);
$eventDispatcher = new EventDispatcher();
Esempio n. 20
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);
 }
 /**
  * @param $config
  */
 protected function sendMockMails()
 {
     $config = (include 'config.php');
     $to = ['email' => $config['email'], 'name' => 'CMB Container'];
     $transport = new Swift_SmtpTransport($config['sender']['server'], $config['sender']['port'], $config['sender']['security']);
     $transport->setUsername($config['sender']['login'])->setPassword($config['sender']['password']);
     $this->mailer = new Swift_Mailer($transport);
     // Send some valid emails
     for ($i = 1; $i <= 2; $i++) {
         $message = $this->makeMessage(new Date('-' . $i . ' days'), md5(rand(0, 1000)), rand(0, 1000) . ',' . rand(1, 99));
         $message->setFrom($config['sender']['email'])->setTo($to['email'], $to['name']);
         $this->mailer->send($message);
     }
     $transport = new Swift_SmtpTransport($config['invalid_sender']['server'], $config['invalid_sender']['port'], $config['invalid_sender']['security']);
     $transport->setUsername($config['invalid_sender']['login'])->setPassword($config['invalid_sender']['password']);
     $this->mailer = new Swift_Mailer($transport);
     // Send some invalid emails
     for ($i = 1; $i <= 2; $i++) {
         $message = $this->makeMessage(new Date('-' . $i . ' days'), md5(rand(0, 1000)), rand(0, 1000));
         $message->setFrom($config['invalid_sender']['email'])->setTo($to['email'], $to['name']);
         $this->mailer->send($message);
     }
 }
Esempio n. 22
0
 /**
  * @return MessengerInterface
  */
 protected function createMailTransport()
 {
     $this->transport = \Swift_SmtpTransport::newInstance($this->mailConfig->getHost(), $this->mailConfig->getPort(), $this->mailConfig->getMailEncryptionType());
     $this->transport->setUsername($this->mailConfig->getSenderUsername())->setPassword($this->mailConfig->getSenderPassword());
     return $this;
 }
Esempio n. 23
0
 /**
  * @return \Swift_Mailer
  */
 protected function createMailer()
 {
     $transport = new \Swift_SmtpTransport($this->host);
     if ($this->port) {
         $transport->setPort($this->port);
     }
     if ($this->username) {
         $transport->setUsername($this->username);
     }
     if ($this->password) {
         $transport->setPassword($this->password);
     }
     if ($this->encryption) {
         $transport->setEncryption($this->encryption);
     }
     return \Swift_Mailer::newInstance($transport);
 }
Esempio n. 24
0
 protected function sendResetEmail($twig, $user_id, $email, $reset_code)
 {
     // Create our Mailer object
     $loader = new ConfigINIFileLoader(APP_DIR . '/config/config.' . APP_ENV . '.ini');
     $config_data = $loader->load();
     $transport = new \Swift_SmtpTransport($config_data['smtp']['host'], $config_data['smtp']['port']);
     if (!empty($config_data['smtp']['user'])) {
         $transport->setUsername($config_data['smtp']['user'])->setPassword($config_data['smtp']['password']);
     }
     if (!empty($config_data['smtp']['encryption'])) {
         $transport->setEncryption($config_data['smtp']['encryption']);
     }
     // Build our email that we will send
     $template = $twig->loadTemplate('emails/reset_password.twig');
     $parameters = array('reset_code' => $reset_code, 'method' => !empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off' ? 'https' : 'http', 'host' => !empty($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : 'localhost', 'user_id' => $user_id, 'email' => $config_data['application']['email'], 'title' => $config_data['application']['title']);
     try {
         $mailer = new \Swift_Mailer($transport);
         $message = new \Swift_Message();
         $message->setTo($email);
         $message->setFrom($template->renderBlock('from', $parameters), $template->renderBlock('from_name', $parameters));
         $message->setSubject($template->renderBlock('subject', $parameters));
         $message->setBody($template->renderBlock('body_text', $parameters));
         $message->addPart($template->renderBlock('body_html', $parameters), 'text/html');
         return $mailer->send($message);
     } catch (\Exception $e) {
         echo $e;
         die;
     }
 }
Esempio n. 25
0
 public function report_mail($options)
 {
     $this->log(__('Reporting via e-mail', 'my-wp-backup'));
     if ('default' === $options['method']) {
         $this->log(__('Sending email via default method', 'my-wp-backup'), 'debug');
         $attachments = array();
         if ('1' === $options['attach']) {
             array_push($attachments, $this->logfile->getPathname());
         }
         add_filter('wp_mail_from', function () use($options) {
             return $options['from'];
         });
         add_filter('wp_mail_from_name', function () use($options) {
             return $options['name'];
         });
         wp_mail($options['address'], $this->format_message($options['title']), $this->format_message($options['message']), array(), $attachments);
     } elseif ('smtp' === $options['method']) {
         $this->log(__('Sending email via SMTP', 'my-wp-backup'), 'debug');
         $security = 'none' === $options['smtp_protocol'] ? null : $options['smtp_protocol'];
         $transport = new \Swift_SmtpTransport($options['smtp_server'], $options['smtp_port'], $security);
         $mailer = new \Swift_Mailer($transport);
         $message = new \Swift_Message();
         $transport->setUsername($options['smtp_username'])->setPassword($options['smtp_password']);
         $message->setSubject($this->format_message($options['title']))->setFrom(array($options['from'] => $options['name']))->setTo(array($options['address']))->setBody($this->format_message($options['message']));
         if ('1' === $options['attach']) {
             $logfile = fopen($this->basedir . 'log.txt', 'r');
             $log = '';
             while (!feof($logfile) && ($line = fgets($logfile))) {
                 $line = json_decode($line, true);
                 $log .= $line['text'] . "\n";
             }
             fclose($logfile);
             $attachment = new \Swift_Attachment($log, 'log.txt', 'text/plain');
             $message->attach($attachment);
         }
         $mailer->send($message);
     } else {
         $this->log(sprintf(__('Unknown e-mail sending method: %s', 'my-wp-backup'), $options['method']), 'error');
     }
     $this->log(__('Done e-mail report', 'my-wp-backup'));
 }
Esempio n. 26
0
 private function createSmtpTransport(array $config = null)
 {
     $transport = new \Swift_SmtpTransport();
     if (!$config) {
         return $transport;
     }
     if (isset($config['host'])) {
         $transport->setHost($config['host']);
     }
     if (isset($config['port'])) {
         $transport->setPort($config['port']);
     }
     if (isset($config['encryption'])) {
         $transport->setEncryption($config['encryption']);
     }
     if (isset($config['username'])) {
         $transport->setUsername($config['username']);
     }
     if (isset($config['password'])) {
         $transport->setPassword($config['password']);
     }
     return $transport;
 }
Esempio n. 27
0
/**
 * Takes care of building the mail body and sending the mail with swiftmailer
 *
 * @param array $data
 * @param array $differences
 */
function dh_send_info_mail(array $data, array $differences)
{
    $data['charset'] = 'utf-8';
    $data['text'] = 'Found ' . count($differences) . ' differences' . PHP_EOL . PHP_EOL;
    $data['subject'] = 'Found ' . count($differences) . 'differences';
    $i = 0;
    foreach ($differences as $difference) {
        /* @var $difference Robo47_DirectoryHasher_Comparator_Difference_Interface */
        $data['text'] .= $i . ')' . PHP_EOL;
        $data['text'] .= $difference->toString() . PHP_EOL . PHP_EOL;
        $i++;
    }
    $smtp = new Swift_SmtpTransport($data['smtp']['host'], $data['smtp']['port']);
    $smtp->setUsername($data['smtp']['username']);
    $smtp->setPassword($data['smtp']['password']);
    $mail = new Swift_Message($data['subject']);
    $mail->setBody($data['text'])->setCharset($data['charset'])->setFrom($data['from']['email'], $data['from']['name'])->setTo($data['to']['email'], $data['to']['name']);
    $swift = new Swift_Mailer($smtp);
    $swift->send($mail);
}
Esempio n. 28
0
 protected function createMailer() : Mailer
 {
     $configuration = $this->options['configuration'];
     $transport = new \Swift_SmtpTransport($configuration->getHost(), $configuration->getPort(), 'tls');
     $transport->setUsername($configuration->getUser());
     $transport->setPassword($configuration->getPass());
     $transport->setStreamOptions(['ssl' => ['verify_peer' => false]]);
     $mailer = Mailer::newInstance($transport);
     if ($this->debug) {
         $logger = new Swift_Plugins_Loggers_EchoLogger();
         $mailer->registerPlugin(new Swift_Plugins_LoggerPlugin($logger));
     }
     return $mailer;
 }
Esempio n. 29
0
$app->get('/unsubscribe/{token}', function ($token) use($app) {
    $repo = $app['orm.em']->getRepository('MikeyMike\\RfcDigestor\\Entity\\Subscriber');
    if ($subscriber = $repo->findOneBy(['unsubscribeToken' => $token])) {
        $em = $app['orm.em'];
        $em->remove($subscriber);
        $em->flush();
        $app['session']->getFlashBag()->add('message', sprintf('You successfully unsubscribed!'));
    }
    return $app->redirect('/');
});
$app['swift'] = function ($app) {
    $conf = $app['config'];
    $transport = new Swift_SmtpTransport();
    $transport->setHost($conf->get('smtp.host'));
    $transport->setPort($conf->get('smtp.port'));
    $transport->setUsername($conf->get('smtp.username'));
    $transport->setPassword($conf->get('smtp.password'));
    $transport->setEncryption($conf->get('smtp.security'));
    $mailer = new Swift_Mailer($transport);
    $mailer->registerPLugin(new CssInlinerPlugin());
    return $mailer;
};
$app['rfc.builder'] = function ($app) {
    return new RfcBuilder($app['config']->get('storagePath'));
};
$app['rfc.service'] = function ($app) {
    return new RfcService($app['rfc.builder'], $app['config']->get('rfcUrl'));
};
$app['diff.service'] = function ($app) {
    return new DiffService();
};
Esempio n. 30
0
 /**
  * Method that sends an email when a talk is created
  *
  * @param Application $app
  * @param string $email
  * @param integer $talk_id
  * @return mixed
  */
 protected function sendSubmitEmail(Application $app, $email, $talk_id)
 {
     $mapper = $app['spot']->mapper('OpenCFP\\Entity\\Talk');
     $talk = $mapper->get($talk_id);
     // Create our Mailer object
     $loader = new ConfigINIFileLoader(APP_DIR . '/config/config.' . APP_ENV . '.ini');
     $config_data = $loader->load();
     $transport = new \Swift_SmtpTransport($config_data['smtp']['host'], $config_data['smtp']['port']);
     if (!empty($config_data['smtp']['user'])) {
         $transport->setUsername($config_data['smtp']['user'])->setPassword($config_data['smtp']['password']);
     }
     if (!empty($config_data['smtp']['encryption'])) {
         $transport->setEncryption($config_data['smtp']['encryption']);
     }
     // Build our email that we will send
     $template = $app['twig']->loadTemplate('emails/talk_submit.twig');
     $parameters = array('email' => $config_data['application']['email'], 'title' => $config_data['application']['title'], 'talk' => $talk->title, 'enddate' => $config_data['application']['enddate']);
     try {
         $mailer = new \Swift_Mailer($transport);
         $message = new \Swift_Message();
         $message->setTo($email);
         $message->setFrom($template->renderBlock('from', $parameters), $template->renderBlock('from_name', $parameters));
         $message->setSubject($template->renderBlock('subject', $parameters));
         $message->setBody($template->renderBlock('body_text', $parameters));
         $message->addPart($template->renderBlock('body_html', $parameters), 'text/html');
         return $mailer->send($message);
     } catch (\Exception $e) {
         echo $e;
         die;
     }
 }