/** * 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(); }
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']); }
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); }
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(); }
/** * 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); }
/** * 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; }
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); }
/** * @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]; }
/** * @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); }
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); }
/** * 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()); } }
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); }
/** * {@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']); }
/** * @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); }
// 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(); $eventDispatcher->addListener(ConsoleEvents::COMMAND, function (ConsoleCommandEvent $event) use($parameters, $logger) {
/** * @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); }
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; }
/** * 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); }
// and entering smtp:yourdomain.com // You'll be given a report stating the server name to use and whether your server supports TLS. // Change smtp.example.org to your own server address below // Enter your email account username and password below also... // If your server supports a security layer (Gmail enforces use of 'tls' and port 587) change port accordingly (587 or 25 usually) and use 'tls' or 'ssl' as a third argument like so: // FOR GMAIL: $transport = Swift_SmtpTransport::newInstance('smtp.gmail.com', 587, 'tls') // GENERIC TLS: $transport = Swift_SmtpTransport::newInstance('mail.mediumra.re', 25, 'tls') // If you choose not to use SSL or TLS then the following could work for you: // $transport = Swift_SmtpTransport::newInstance('mail.mediumra.re', 25) // or if you prefer/need to fall back to use PHP's inbuilt mail() function: // $transport = Swift_MailTransport::newInstance(); $email = "*****@*****.**"; $password = "******"; $transport = new \Swift_SmtpTransport("smtp.gmail.com", 465, "ssl"); $transport->setUsername($email); $transport->setPassword($password); $mailer = new \Swift_Mailer($transport); $message = new \Swift_Message(); // ...configure message... $message->setFrom($email); $mailer->send($message); // Creating the message text using fields sent through POST foreach ($_POST as $key => $value) { $messageText .= ucfirst($key) . ": " . $value . "\n\n"; } // You can change "A message from Pivot Template Form" to your own subject if you want. $message = Swift_Message::newInstance('A message from Pivot Template Form')->setFrom(array($_POST['email'] => $_POST['name']))->setTo(array('*****@*****.**' => 'Devin Mathew Robbins'))->setBody($messageText); // ^ ^ // Your email address_/ Your name_/ // Send the message or catch an error if it occurs. try {
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; }
$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(); }; $app['slack.api'] = function ($app) {
/** * 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); }