mailer = $mailer; $this->newsletter = $newsletter; } /** * {@inheritdoc} */ protected function configure() { $this ->setName('potage:mail:send') ->setDescription("Test d'envoi de mail(s) !") ->setHelp('Must precise if send a test mail, a single mail or a mailing ') ->addArgument('what', InputArgument::REQUIRED, '"test", "single" or "mailing" ?'); } /** * @param InputInterface $input * @param OutputInterface $output * @return int|null|void * @throws \Twig_Error_Loader * @throws \Twig_Error_Runtime * @throws \Twig_Error_Syntax */ protected function execute(InputInterface $input, OutputInterface $output) { /** * @var Lettre $lettre */ $lettre = $this->getContainer()->get('doctrine')->getManager() ->getRepository('PotageBundle:Lettre') ->findOneForSend(7); $what = $input->getArgument('what'); switch ($what) { case "test": $message = (new \Swift_Message('[Docker][Symfony][cli] Mail de test ')) ->setFrom('postmaster@potage.domainepublic.site') ->setTo('mat@collectifs.net') ->setBody( 'coucou, ceci est un test', 'text/html' ); $this->mailer->send($message); $output->writeln('[Docker][Symfony][cli] Mail sent.'); break; case "single": $to = array( 'email' => 'mat@collectifs.net', 'fullName' => 'Matla', 'token' => null ); $retour = $this->newsletter->sendLettre( $to, "[Docker][Symfony][cli][infolettre][single] Mail de test", $this->newsletter->lettreTobody($lettre) ); $retourMsg = ( $retour === 1 ) ? "\e[1;32mSent\e[0m\n" : "\e[1;31mError\e[0m\n"; $output->writeln('Sending mail .. '. $retourMsg); break; case "mailing": $retour = $this->newsletter->sendLettreToGroup($lettre); for ($i = 0; $i < count($retour); $i++) { $output->writeln($i .' | '. $retour[$i]['to'] .' | '. $retour[$i]['result']); } break; } } }