src/Ovh/OvhSend.php line 1051

Open in your IDE?
  1. <?php
  2. /**
  3.  * Created by PhpStorm.
  4.  * User: anthony
  5.  * Date: 25/05/18
  6.  * Time: 11:56
  7.  */
  8. namespace App\Ovh;
  9. use App\Entity\Actualite;
  10. use App\Entity\Auth\AuthUser;
  11. use App\Entity\DemandeDeConge;
  12. use App\Entity\Email\AdresseMailVerif;
  13. use App\Entity\Email\EmailRetour;
  14. use App\Entity\Mailling;
  15. use App\Entity\PieceJointeMailling;
  16. use App\Entity\Pressroom\PressroomCommunique;
  17. use App\Entity\Suivi;
  18. use App\Entity\User;
  19. use App\Service\MaillingEnCour\MaillingEnCour;
  20. use App\Service\Utilitaire\AnomalieGestion;
  21. use Doctrine\Common\Collections\ArrayCollection;
  22. use Doctrine\ORM\EntityManager;
  23. use Doctrine\ORM\EntityManagerInterface;
  24. use Swift_Mailer;
  25. use Swift_Message;
  26. use Swift_Plugins_LoggerPlugin;
  27. use Swift_Plugins_Loggers_ArrayLogger;
  28. use Swift_SmtpTransport;
  29. use Symfony\Component\HttpKernel\KernelInterface;
  30. use Twig\Environment;
  31. use Twig\Error\LoaderError;
  32. use Twig\Error\RuntimeError;
  33. use Twig\Error\SyntaxError;
  34. use Twig\Loader\FilesystemLoader;
  35. class OvhSend
  36. {
  37.     private $ovhHelper;
  38.     private $kernel;
  39.     private $mailer;
  40.     private $anomalieGestion;
  41.     private $authUser;
  42.     private $em;
  43.     /**
  44.     * @var Environment $twig
  45.     */
  46.     private $twig;
  47.     /**
  48.      * OvhSend constructor.
  49.      */
  50.     public function __construct(OvhHelper $ovhHelperKernelInterface $kernelAnomalieGestion $anomalieGestionEntityManagerInterface $em)
  51.     {
  52.         $this->authUser null;
  53.         $this->nbMailEnvoye 0;
  54.         $this->anomalieGestion $anomalieGestion;
  55.         $this->ovhHelper $ovhHelper;
  56.         $this->kernel $kernel;
  57.         $this->em $em;
  58.         $loader = new FilesystemLoader(__DIR__.'/views/');
  59.         $this->twig = new Environment($loader, array());
  60.     }
  61.     public function sendMailConfirmationDemandeConge(DemandeDeConge $demandeDeConge){
  62.         $template $this->twig->load('demandeCongeValidation.html.twig');
  63.         $message = (new Swift_Message('validation demande de congé'))
  64.             ->setFrom('louis@escalconsulting.com')
  65.             ->setTo($demandeDeConge->getAuthUser()->getUser()->getEmail())
  66.             ->setSubject('validation demande de congé')
  67.             ->setBody(
  68.                 $template->render(array('demandeDeConge' => $demandeDeConge)),
  69.                 'text/html'
  70.             )
  71.             ->setReplyTo('louis@escalconsulting.com');
  72.         $message->attach(\Swift_Attachment::fromPath($this->kernel->getRootDir() . '/../public/Interne/demandeConge/'.$demandeDeConge->getDebutConge()->format('Y-m-d').'demandeConge'.
  73.             $demandeDeConge->getAuthUser()->getUser()->getNom().'.pdf'));
  74.         $authUser $this->em->getRepository('App:Auth\AuthUser')
  75.             ->findOneBy(['username' => 'louis']);
  76.         /** @var AuthUser $authUser */
  77.         $mail $authUser->getUser()->getEmail();
  78.         $password =  $authUser->getPasswordMail();
  79.         $transport = new Swift_SmtpTransport('exchange.escalconsulting.com'587'tls');
  80.         $transport
  81.             ->setUsername($mail)
  82.             ->setPassword($password);
  83.         $mailer = new Swift_Mailer($transport);
  84.         $logger = new Swift_Plugins_Loggers_ArrayLogger;
  85.         $mailer->registerPlugin(new Swift_Plugins_LoggerPlugin($logger));
  86.         $mailer->send($message$failRecipient);
  87.     }
  88.     public function sendMailCongeCopil(DemandeDeConge $demandeDeConge) {
  89.         $template $this->twig->load('notificationCongeCopil.html.twig');
  90.         $message = (new Swift_Message('Notification Copil'))
  91.             ->setFrom('notification@escalconsulting.com')
  92.             ->setTo('copil@escalconsulting.com')
  93.             ->setSubject('Congé  '.$demandeDeConge->getAuthUser()->getUser()->getPrenom()
  94.                 . ' ' .$demandeDeConge->getAuthUser()->getUser()->getNom())
  95.             ->setBody(
  96.                 $template->render(array('demandeDeConge' => $demandeDeConge)),
  97.                 'text/html'
  98.             )
  99.             ->setReplyTo('louis@escalconsulting.com');
  100.         $authUser $this->em->getRepository('App:Auth\AuthUser')
  101.             ->findOneBy(['username' => 'Notification']);
  102.         /** @var AuthUser $authUser */
  103.         $mail $authUser->getUser()->getEmail();
  104.         $password =  $authUser->getPasswordMail();
  105.         $transport = new Swift_SmtpTransport('exchange.escalconsulting.com'587'tls');
  106.         $transport
  107.             ->setUsername($mail)
  108.             ->setPassword($password);
  109.         $mailer = new Swift_Mailer($transport);
  110.         $logger = new Swift_Plugins_Loggers_ArrayLogger;
  111.         $mailer->registerPlugin(new Swift_Plugins_LoggerPlugin($logger));
  112.         $mailer->send($message$failRecipient);
  113.     }
  114.     public function getContactSend(Mailling $mailling){
  115.         $post = [
  116.             'login' => 'Systeme',
  117.             'password' => 'i5iJ;5@J7',
  118.         ];
  119.         $ch curl_init('extranet.escalconsulting.com/identification.php');
  120.         curl_setopt($chCURLOPT_RETURNTRANSFERtrue);
  121.         curl_setopt($chCURLOPT_POSTFIELDS$post);
  122.         curl_setopt($chCURLOPT_COOKIESESSIONtrue);
  123.         curl_setopt($chCURLOPT_HEADER1);
  124.         $response curl_exec($ch);
  125.         curl_close($ch);
  126.         preg_match_all('/^Set-Cookie:\s*([^;]*)/mi'$response$matches);
  127.         foreach($matches[1] as $item) {
  128.             parse_str($item$cookie);
  129.             $cookiesRetour $cookie['PHPSESSID'];
  130.         }
  131.         $curl curl_init();
  132.         curl_setopt($curlCURLOPT_URL'extranet.escalconsulting.com/mail_cms.php?action=lstuniq_frame&ID_mail=' $mailling->getAncienId());
  133.         curl_setopt($curlCURLOPT_COOKIE,"PHPSESSID=".$cookiesRetour);
  134.         curl_setopt($curlCURLOPT_COOKIESESSIONtrue);
  135.         curl_setopt($curlCURLOPT_RETURNTRANSFERtrue);
  136.         curl_setopt($curlCURLOPT_FOLLOWLOCATIONtrue);
  137.         curl_setopt($curlCURLOPT_SSL_VERIFYPEERfalse);
  138.         $return curl_exec($curl);
  139.         curl_close($curl);
  140.         $curl curl_init();
  141.         curl_setopt_array($curl, array(
  142.             CURLOPT_RETURNTRANSFER => true,
  143.             CURLOPT_URL => 'extranet.escalconsulting.com/information/getInfoListMailling.php?id=' $mailling->getAncienId(),
  144.         ));
  145.         $retourUserList curl_exec($curl);
  146.         $retourUserList substr($retourUserList0, -1);
  147.         curl_close($curl);
  148.         $usersSend explode('~'$retourUserList);
  149.         return $usersSend;
  150.     }
  151.     public function verifMail($contactEmail) {
  152.         $blackList $this->em->getRepository('App:BlackList')->findOneBy(['email' => $contactEmail['email']]);
  153.         if($blackList){
  154.             return false;
  155.         }
  156.         $emailVerif $this->em->getRepository('App:Email\AdresseMailVerif')->findOneBy(['email' => $contactEmail['email']]);
  157.         if($emailVerif){
  158.             /** @var $emailVerif AdresseMailVerif */
  159.             if($emailVerif->getSafeToSend() == 0){
  160.                 if($emailVerif->getReason() != 'Unreachable'){
  161.                     return false;
  162.                 }
  163.             }
  164.         }
  165.         return true;
  166.     }
  167.     public function getNextMail($idcontact$contactEmail) {
  168.         $url="localhost:81/information/getNextMailByListId.php?id=".$idcontact;
  169.         $postFields$contactEmail;
  170.         $options=array(
  171.             CURLOPT_URL            => $url,
  172.             CURLOPT_RETURNTRANSFER => true,
  173.             CURLOPT_HEADER         => false,
  174.             CURLOPT_FAILONERROR    => true,
  175.             CURLOPT_POST           => true,
  176.             CURLOPT_POSTFIELDS     => array("idContact"=>json_encode($postFields))
  177.         );
  178.         $curl=curl_init();
  179.         curl_setopt_array($curl,$options);
  180.         $content=curl_exec($curl);
  181.         dump($content);
  182.         die();
  183.         return $content;
  184. }
  185.     public function getContactSend2(Mailling $mailling) {
  186.         $curl curl_init();
  187.         $url 'extranet.escalconsulting.com/information/genererMailContactMailling.php?id=' $mailling->getAncienId();
  188.         curl_setopt($curlCURLOPT_URL$url);
  189.         curl_setopt($curlCURLOPT_COOKIESESSIONtrue);
  190.         curl_setopt($curlCURLOPT_RETURNTRANSFERtrue);
  191.         curl_setopt($curlCURLOPT_FOLLOWLOCATIONtrue);
  192.         curl_setopt($curlCURLOPT_SSL_VERIFYPEERfalse);
  193.         $return curl_exec($curl);
  194.         curl_close($curl);
  195.         $contactsEmail json_decode($returntrue);
  196.         $idsContactWithoutMail = [];
  197.         $idContactAEnvoyer = [];
  198.         $mailFalse = [];
  199.         foreach ($contactsEmail as $idContact => $contactEmail) {
  200.             $emailOK false;
  201.             $idContactTraite $idContact;
  202.             $contactEmailTraite $contactEmail;
  203.             while ($emailOK == false) {
  204.                 $emailOK $this->verifMail($contactEmailTraite);
  205.                 if ($emailOK == false) {
  206.                     $mailFalse[]=$contactEmailTraite;
  207.                     $contsEmail $this->getNextMail($idContactTraite,$contactEmailTraite);
  208.                     dump($contsEmail);
  209.                     if (count($contsEmail) == 0) {
  210.                         $idsContactWithoutMail[] = $idContactTraite;
  211.                         $emailOK true;
  212.                     } else if (count($contsEmail) != 1) {
  213.                         dump("Impossible");
  214.                         die();
  215.                     }
  216.                     foreach ($contsEmail as $idCont => $contEmail) {
  217.                         $idContactTraite $idCont;
  218.                         $contactEmailTraite $contEmail;
  219.                     }
  220.                 } else {
  221.                    $a=1;
  222.                     //die();
  223.                     //idContactAEnvoyer[$idContactTraite] = $contactEmailTraite;
  224.                 }
  225.             }
  226.         }
  227.         $idsCanBeBetter = [];
  228.         foreach ($contactsEmail as $idContact => $contactEmail){
  229.             $emailVerif $this->em->getRepository('App:Email\AdresseMailVerif')->findOneBy(['email' => $contactEmail['email']]);
  230.             if($emailVerif){
  231.                 /** @var $emailVerif AdresseMailVerif */
  232.                 if($emailVerif->getRole() == 1){
  233.                     $idsCanBeBetter[$idContact] = $contactEmail;
  234.                 }
  235.             }
  236.         }
  237.         dump(count($contactsEmail));
  238.         die();
  239.     }
  240.     public function miseAjourPressroom(Mailling $mailling$update 0){
  241.         $curl curl_init();
  242.         curl_setopt_array($curl, array(
  243.             CURLOPT_RETURNTRANSFER => 1,
  244.             CURLOPT_URL => 'extranet.escalconsulting.com/information/getPressroomId.php?id=' $mailling->getClient()->getAncienId(),
  245.         ));
  246.         $idPressroom curl_exec($curl);
  247.         curl_close($curl);
  248.         $file $this->kernel->getRootDir() . '/../public/maillings/'.$mailling->getId().'.pdf';
  249.         if($mailling->getClient()->getPressroom()){
  250.             $pressroom $mailling->getClient()->getPressroom();
  251.             $pressroomComunique = new PressroomCommunique();
  252.             $pressroomComunique->setAncienId($mailling->getAncienId());
  253.             $pressroomComunique->setDate(new \DateTime('now'));
  254.             if($mailling->getObjetCour()){
  255.                 $pressroomComunique->setNom($mailling->getObjetCour());
  256.             } else {
  257.                 $pressroomComunique->setNom($mailling->getObjet());
  258.             }
  259.             $pressroomComunique->setPdf(true);
  260.             // recuperation et création des paths
  261.             $pathPressroomFile $this->kernel->getRootDir() . '/../public/pressroomClient/' $pressroom->getId();
  262.             if(!file_exists($pathPressroomFile)){
  263.                 mkdir($pathPressroomFile,0777);
  264.             }
  265.             $pathPressroomCommunique $pathPressroomFile '/communique/';
  266.             if(!file_exists($pathPressroomCommunique)){
  267.                 mkdir($pathPressroomCommunique,0777);
  268.             }
  269.             // recupération du pdf
  270.             $communiqueFile  $this->kernel->getRootDir() . '/../public/maillings/'$mailling->getId() . '.pdf';
  271.             if(file_exists($communiqueFile)){
  272.                 copy($communiqueFile$pathPressroomCommunique$mailling->getAncienId() . '.pdf');
  273.                 $pressroomComunique->setPdf(true);
  274.             }
  275.             // recuperation photo
  276.             if($mailling->getPhoto()){
  277.                 $explodeUrl explode('.'$mailling->getPhoto()->getUrl());
  278.                 $extension end($explodeUrl);
  279.                 $url 'extranet.escalconsulting.com/photocp/'$mailling->getPhoto()->getUrl();
  280.                 $c curl_init();
  281.                 curl_setopt($cCURLOPT_URL$url);
  282.                 curl_setopt($cCURLOPT_RETURNTRANSFERtrue);
  283.                 curl_setopt($cCURLOPT_HEADERfalse);
  284.                 $output curl_exec($c);
  285.                 curl_close($c);
  286.                 file_put_contents($pathPressroomFile'/communique/'$mailling->getAncienId() . '.' .
  287.                     $extension  $output);
  288.                 $pressroomComunique->setPhoto($extension);
  289.                 $pressroomComunique->setDate($mailling->getDateEnvoi());
  290.             }
  291.             $pressroom->addPressroomCommunique($pressroomComunique);
  292.             $this->em->persist($pressroomComunique);
  293.             $this->em->persist($pressroom);
  294.             $this->em->flush();
  295.         }
  296.     }
  297.     public function setMaillingSend(Mailling $mailling){
  298.         if($mailling->getTypeMail() == "Coupure"){
  299.             foreach ($mailling->getPiecesJointes() as $piecesJointe){
  300.                 /** @var PieceJointeMailling $piecesJointe */
  301.                  $idCoupure $piecesJointe->getCoupure()->getAncienId();
  302.                 $curl curl_init();
  303.                 curl_setopt_array($curl, array(
  304.                     CURLOPT_RETURNTRANSFER => 1,
  305.                     CURLOPT_URL => 'extranet.escalconsulting.com/information/setCoupureSend.php?id=' $idCoupure,
  306.                 ));
  307.                 $coupureSend curl_exec($curl);
  308.                 curl_close($curl);
  309.                 $piecesJointe->getCoupure()->setEnvoyer(true);
  310.                 $this->em->persist($piecesJointe->getCoupure());
  311.                 $this->em->flush();
  312.             }
  313.         } else {
  314.             $curl curl_init();
  315.             curl_setopt_array($curl, array(
  316.                 CURLOPT_RETURNTRANSFER => 1,
  317.                 CURLOPT_URL => 'extranet.escalconsulting.com/information/setMaillingSend.php?id=' $mailling->getAncienId(),
  318.             ));
  319.             $maillingSend curl_exec($curl);
  320.             curl_close($curl);
  321.         }
  322.     }
  323.     public function sendMailEnvoie(\App\Entity\MaillingEnCour $maillingEnCour){
  324.         $endMailling false;
  325.         $maillingEnCour->setDestinataire(trim($maillingEnCour->getDestinataire()));
  326.         if($maillingEnCour->getTypeMail() == "mailling"){
  327.             $message $this->getMessageMaillingType($maillingEnCour);
  328.         } elseif ($maillingEnCour->getTypeMail() == "veille"){
  329.             $message $this->getMessageVeilleType($maillingEnCour);
  330.         } elseif ($maillingEnCour->getTypeMail() == "test"){
  331.             $message $this->getMessageMaillingTestType($maillingEnCour);
  332.         } elseif ($maillingEnCour->getTypeMail() == "confirmationBegin"){
  333.             $message $this->getMessageConfirmation($maillingEnCour,'begin');
  334.         } elseif ($maillingEnCour->getTypeMail() == "confirmationEnd"){
  335.             $message $this->getMessageConfirmation($maillingEnCour,'end');
  336.             if($maillingEnCour->getDestinataire() == 'informatique@escalconsulting.com')
  337.             $endMailling true;
  338.         }
  339.         if($message != false){
  340.             if(is_array($message)){
  341.                 foreach ($message as $mess){
  342.                     $this->sendMail($mess$maillingEnCour);
  343.                 }
  344.                 return false;
  345.             } else {
  346.                     $this->sendMail($message$maillingEnCour);
  347.             }
  348.         }
  349.         if($endMailling){
  350.             return $maillingEnCour;
  351.         }
  352.         return false;
  353.     }
  354.     public function finMailling(\App\Entity\MaillingEnCour $maillingEnCour){
  355.         $maillingEnCourMailling $this->em->getRepository('App:MaillingEnCour')
  356.             ->findBy(['mailling' => $maillingEnCour->getMailling(), 'typeMail' => 'mailling''envoyer' => true]);
  357.         $maillingEnCour->getMailling()->setNbMailEnvoye(count($maillingEnCourMailling));
  358.         $maillingEnCour->getMailling()->setEnvoyer(true);
  359.         $maillingEnCour->getMailling()->setDateEnvoi(new \DateTime('now'));
  360.         $this->em->persist($maillingEnCour->getMailling());
  361.         $this->em->flush();
  362.         $this->setMaillingSend($maillingEnCour->getMailling());
  363.         if($maillingEnCour->getMailling()->getTypeMail() != "Coupure") {
  364.             $this->miseAjourPressroom($maillingEnCour->getMailling());
  365.         }
  366.     }
  367.     public function getMessageConfirmation(\App\Entity\MaillingEnCour $maillingEnCour$status){
  368.         $from $this->getFrom($maillingEnCour);
  369.         if($status == 'begin'){
  370.             $from $this->getFrom($maillingEnCour);
  371.             $mailling $maillingEnCour->getMailling();
  372.             $pathRSA $this->kernel->getRootDir() . '/../public/Interne/RSA';
  373.             $privateKeyRSA file_get_contents($pathRSA);
  374.             $domainName 'escalconsulting.com';
  375.             $selector '1515841257';
  376.             $signer = new \Swift_Signers_DKIMSigner($privateKeyRSA$domainName$selector);
  377.             if($mailling->getTypeMail() != 'CP'){
  378.             $size 0;
  379.             $pathCoupure $this->kernel->getRootDir() . '/../public/coupures/';
  380.             $iterator $mailling->getPiecesJointes()->getIterator();
  381.             $iterator->uasort(function ($a$b) {
  382.                 return ($a->getCoupure()->getDateParution() < $b->getCoupure()->getDateParution()) ? -1;
  383.             });
  384.             $mailling->setPiecesJointes(new ArrayCollection(iterator_to_array($iterator)));
  385.             foreach ($mailling->getPiecesJointes() as $pieceJointe){
  386.                 $size $size filesize $pathCoupure $pieceJointe->getUrl());
  387.             }
  388.             $coupuresMessage = [];
  389.             if($size 10000000){
  390.                 $coupuresMessage[] = $mailling->getPiecesJointes();
  391.             } else {
  392.                 $ratio $size 10000000;
  393.                 $ratio floor($ratio) + 1;
  394.                 $sizeMid $size $ratio;
  395.                 $sizeCoupure 0;
  396.                 $pieceJointeMail = [];
  397.                 foreach ($mailling->getPiecesJointes() as $pieceJointe){
  398.                     if($sizeCoupure $sizeMid){
  399.                         $coupuresMessage[] = $pieceJointeMail;
  400.                         $pieceJointeMail = [];
  401.                         $sizeCoupure 0;
  402.                     }
  403.                     $pieceJointeMail[] = $pieceJointe;
  404.                     $sizeCoupure $sizeCoupure filesize $pathCoupure $pieceJointe->getUrl());
  405.                 }
  406.                 $coupuresMessage[] = $pieceJointeMail;
  407.             }
  408.             $messages = [];
  409.             $i 1;
  410.             foreach ($coupuresMessage as $coupureMessage) {
  411.                 $template $this->twig->load('mailCoupure.html.twig');
  412.                 if (count($coupuresMessage) == 1) {
  413.                     $objetMail $mailling->getNom();
  414.                 } else {
  415.                     $objetMail $mailling->getNom() .'  '$i '/' count($coupuresMessage);
  416.                 }
  417.                 $debut '';
  418.                 $fin '';
  419.                 if($i == 1){
  420.                     $debut $mailling->getDebutMailCoupure();
  421.                 }
  422.                 if($i == count($coupuresMessage)){
  423.                     $fin $mailling->getFinMailCoupure();
  424.                 }
  425.                 $message = (new \Swift_Message($objetMail))
  426.                     ->setFrom($from)
  427.                     ->setTo($maillingEnCour->getDestinataire())
  428.                     ->setSubject($objetMail)
  429.                     ->setBody($template->render(
  430.                         array('mailling' => $mailling'coupureMessage' => $coupureMessage,
  431.                             'user' => $mailling->getReplyTo(), 'debut' => $debut'fin' => $fin,
  432.                             'logo' => $mailling->getClient()->getLogo()->getUrl(),)),
  433.                         'text/html')
  434.                     ->setReplyTo($mailling->getReplyTo()->getUser()->getEmail());
  435.                 $message->attachSigner($signer);
  436.                 /** @var PieceJointeMailling $pieceJointe */
  437.                 foreach ($coupureMessage as $pieceJointe) {
  438.                     $message->attach(\Swift_Attachment::fromPath($pathCoupure$pieceJointe->getUrl()));
  439.                 }
  440.                 $i $i 1;
  441.                 $messages[] = $message;
  442.             }
  443.             return $messages;
  444.         } else {
  445.                 $rand '&'.rand(0,1000000).'='.rand(0,1000000);
  446.                 if (strlen($mailling->getColor())==7){
  447.                     $color $mailling->getColor();
  448.                 } else {
  449.                     $color "#F57E60";
  450.                 }
  451.                 $template $this->twig->load('mailConfirmation.html.twig');
  452.                 $message = (new \Swift_Message($mailling->getObjetCour()))
  453.                     ->setFrom($from)
  454.                     ->setTo($maillingEnCour->getDestinataire())
  455.                     ->setSubject($mailling->getObjetCour())
  456.                     ->setBody(
  457.                         $template->render(array('mailling' => $mailling'user' => $mailling->getReplyTo(),
  458.                             'logo' => $mailling->getClient()->getLogo()->getUrl(),
  459.                             'rand' => $rand'color' => $color)),
  460.                         'text/html'
  461.                     )
  462.                     ->setReplyTo($mailling->getReplyTo()->getUser()->getEmail());
  463.                 if($mailling->getId() == 6824){
  464.                     $pathfile $this->kernel->getRootDir() . '/../public/Interne/';
  465.                     $message->attach(\Swift_Attachment::fromPath($pathfile'infographie.jpg'));
  466.                 }
  467.                 $message->attachSigner($signer);
  468.                 /** @var PieceJointeMailling $piecesJointe */
  469.                 foreach ($mailling->getPiecesJointes() as $piecesJointe){
  470.                     $message->attach(\Swift_Attachment::fromPath($this->kernel->getRootDir() . '/../public/maillings/'$mailling->getAncienId() . '/' $piecesJointe->getUrl()));
  471.                 }
  472.             }
  473.             return $message;
  474.         }
  475.         $template $this->twig->load('mailConfirmationFin.html.twig');
  476.         if($maillingEnCour->getMailling()->getTypeMail() == 'Coupure'){
  477.             $objet $maillingEnCour->getMailling()->getObjet();
  478.         } else {
  479.             $objet $maillingEnCour->getMailling()->getObjetCour();
  480.         }
  481.             $finObjet ' a été envoyé';
  482.         $message = (new \Swift_Message($objet $finObjet))
  483.             ->setFrom($from)
  484.             ->setTo($maillingEnCour->getDestinataire())
  485.             ->setSubject($objet $finObjet)
  486.             ->setBody(
  487.                 $template->render(array('mailling' => $maillingEnCour->getMailling())),
  488.                 'text/html'
  489.             );
  490.         return $message;
  491.     }
  492.     public function getMessageVeilleType(\App\Entity\MaillingEnCour $maillingEnCour){
  493.         $from $this->getFrom($maillingEnCour);
  494.         $template $this->twig->load('veille.html.twig');
  495.         $message = (new \Swift_Message('Veille du '$maillingEnCour->getVeille()->getDate()->format('d/m/Y')))
  496.             ->setFrom($from)
  497.             ->setTo($maillingEnCour->getDestinataire())
  498.             ->setSubject('Veille du '$maillingEnCour->getVeille()->getDate()->format('d/m/Y'))
  499.             ->setBody(
  500.                 $template->render(array('veille' => $maillingEnCour->getVeille())),
  501.                 'text/html'
  502.             );
  503.         return $message;
  504.     }
  505.     public function getMessageMaillingTestType(\App\Entity\MaillingEnCour $maillingEnCour){
  506.         $from $this->getFrom($maillingEnCour);
  507.         $mailling $maillingEnCour->getMailling();
  508.         $pathRSA $this->kernel->getRootDir() . '/../public/Interne/RSA';
  509.         $privateKeyRSA file_get_contents($pathRSA);
  510.         $domainName 'escalconsulting.com';
  511.         $selector '1515841257';
  512.         $signer = new \Swift_Signers_DKIMSigner($privateKeyRSA$domainName$selector);
  513.         $rand '&'.rand(0,1000000).'='.rand(0,1000000);
  514.         if($mailling->getTypeMail() != 'CP'){
  515.             $size 0;
  516.             $pathCoupure $this->kernel->getRootDir() . '/../public/coupures/';
  517.             $iterator $mailling->getPiecesJointes()->getIterator();
  518.             $iterator->uasort(function ($a$b) {
  519.                 return ($a->getCoupure()->getDateParution() < $b->getCoupure()->getDateParution()) ? -1;
  520.             });
  521.             $mailling->setPiecesJointes(new ArrayCollection(iterator_to_array($iterator)));
  522.             foreach ($mailling->getPiecesJointes() as $pieceJointe){
  523.                 $size $size filesize $pathCoupure $pieceJointe->getUrl());
  524.             }
  525.             $coupuresMessage = [];
  526.             if($size 10000000){
  527.                 $coupuresMessage[] = $mailling->getPiecesJointes();
  528.             } else {
  529.                 $ratio $size 10000000;
  530.                 $ratio floor($ratio) + 1;
  531.                 $sizeMid $size $ratio;
  532.                 $sizeCoupure 0;
  533.                 $pieceJointeMail = [];
  534.                 foreach ($mailling->getPiecesJointes() as $pieceJointe){
  535.                     if($sizeCoupure $sizeMid){
  536.                         $coupuresMessage[] = $pieceJointeMail;
  537.                         $pieceJointeMail = [];
  538.                         $sizeCoupure 0;
  539.                     }
  540.                     $pieceJointeMail[] = $pieceJointe;
  541.                     $sizeCoupure $sizeCoupure filesize $pathCoupure $pieceJointe->getUrl());
  542.                 }
  543.                 $coupuresMessage[] = $pieceJointeMail;
  544.             }
  545.             $messages = [];
  546.             $i 1;
  547.             foreach ($coupuresMessage as $coupureMessage) {
  548.                 $template $this->twig->load('mailTestCoupure.html.twig');
  549.                 if (count($coupuresMessage) == 1) {
  550.                     $objetMail $mailling->getNom();
  551.                 } else {
  552.                     $objetMail $mailling->getNom() .'  '$i '/' count($coupuresMessage);
  553.                 }
  554.                 $debut '';
  555.                 $fin '';
  556.                 if($i == 1){
  557.                     $debut $mailling->getDebutMailCoupure();
  558.                 }
  559.                 if($i == count($coupuresMessage)){
  560.                     $fin $mailling->getFinMailCoupure();
  561.                 }
  562.                 $message = (new \Swift_Message($objetMail))
  563.                     ->setFrom($from)
  564.                     ->setTo($maillingEnCour->getDestinataire())
  565.                     ->setSubject($objetMail)
  566.                     ->setBody($template->render(
  567.                         array('mailling' => $mailling'coupureMessage' => $coupureMessage,
  568.                             'user' => $mailling->getReplyTo(), 'debut' => $debut'fin' => $fin,  'rand' => $rand,
  569.                             'logo' => $mailling->getClient()->getLogo()->getUrl(),)),
  570.                         'text/html')
  571.                     ->setReplyTo($mailling->getReplyTo()->getUser()->getEmail());
  572.                 $message->attachSigner($signer);
  573.                 /** @var PieceJointeMailling $pieceJointe */
  574.                 foreach ($coupureMessage as $pieceJointe) {
  575.                     $message->attach(\Swift_Attachment::fromPath($pathCoupure$pieceJointe->getUrl()));
  576.                 }
  577.                 $i $i 1;
  578.                 $messages[] = $message;
  579.             }
  580.             return $messages;
  581.         } else {
  582.             if (strlen($mailling->getColor())==7){
  583.                 $color $mailling->getColor();
  584.             } else {
  585.                 $color "#F57E60";
  586.             }
  587.             if($mailling->getId()== 5517 or $mailling->getId() == 5899){
  588.                 $template $this->twig->load('mailClient/logoFCAtest.html.twig');
  589.             } else {
  590.                 $template $this->twig->load('mailTestNew.html.twig');
  591.             }
  592.             $message = (new \Swift_Message($mailling->getObjetCour()))
  593.                 ->setFrom($from)
  594.                 ->setTo($maillingEnCour->getDestinataire())
  595.                 ->setSubject($mailling->getObjetCour())
  596.                 ->setBody(
  597.                     $template->render(array('mailling' => $mailling'user' => $mailling->getReplyTo(),
  598.                         'logo' => $mailling->getClient()->getLogo()->getUrl(),
  599.                         'rand' => $rand'color' => $color)),
  600.                     'text/html'
  601.                 )
  602.                 ->setReplyTo($mailling->getReplyTo()->getUser()->getEmail());
  603.             if($mailling->getId() == 6824){
  604.                 $pathfile $this->kernel->getRootDir() . '/../public/Interne/';
  605.                $message->attach(\Swift_Attachment::fromPath($pathfile'infographie.jpg'));
  606.             }
  607.             $message->attachSigner($signer);
  608.             /** @var PieceJointeMailling $piecesJointe */
  609.             foreach ($mailling->getPiecesJointes() as $piecesJointe){
  610.                 $message->attach(\Swift_Attachment::fromPath($this->kernel->getRootDir() . '/../public/maillings/'$mailling->getAncienId() . '/' $piecesJointe->getUrl()));
  611.             }
  612.         }
  613.         return $message;
  614.     }
  615.     public function getMessageMaillingType(\App\Entity\MaillingEnCour $maillingEnCour){
  616.         if(filter_var(trim($maillingEnCour->getDestinataire()), FILTER_VALIDATE_EMAIL)){
  617.             $from $this->getFrom($maillingEnCour);
  618.             $mailling $maillingEnCour->getMailling();
  619.             // dkim sigbnature electronique des mails lors de l'envoie
  620.             $pathRSA $this->kernel->getRootDir() . '/../public/Interne/RSA';
  621.             $privateKeyRSA file_get_contents($pathRSA);
  622.             $domainName 'escalconsulting.com';
  623.             $selector '1515841257';
  624.             $signer = new \Swift_Signers_DKIMSigner($privateKeyRSA$domainName$selector);
  625.             if($mailling->getTypeMail() != 'CP'){
  626.                 $size 0;
  627.                 $pathCoupure $this->kernel->getRootDir() . '/../public/coupures/';
  628.                 $iterator $mailling->getPiecesJointes()->getIterator();
  629.                 $iterator->uasort(function ($a$b) {
  630.                     return ($a->getCoupure()->getDateParution() < $b->getCoupure()->getDateParution()) ? -1;
  631.                 });
  632.                 $mailling->setPiecesJointes(new ArrayCollection(iterator_to_array($iterator)));
  633.                 foreach ($mailling->getPiecesJointes() as $pieceJointe){
  634.                     $size $size filesize $pathCoupure $pieceJointe->getUrl());
  635.                 }
  636.                 $coupuresMessage = [];
  637.                 if($size 10000000){
  638.                     $coupuresMessage[] = $mailling->getPiecesJointes();
  639.                 } else {
  640.                     $ratio $size 10000000;
  641.                     $ratio floor($ratio) + 1;
  642.                     $sizeMid $size $ratio;
  643.                     $sizeCoupure 0;
  644.                     $pieceJointeMail = [];
  645.                     foreach ($mailling->getPiecesJointes() as $pieceJointe){
  646.                         if($sizeCoupure $sizeMid){
  647.                             $coupuresMessage[] = $pieceJointeMail;
  648.                             $pieceJointeMail = [];
  649.                             $sizeCoupure 0;
  650.                         }
  651.                         $pieceJointeMail[] = $pieceJointe;
  652.                         $sizeCoupure $sizeCoupure filesize $pathCoupure $pieceJointe->getUrl());
  653.                     }
  654.                     $coupuresMessage[] = $pieceJointeMail;
  655.                 }
  656.                 $messages = [];
  657.                 $i 1;
  658.                 foreach ($coupuresMessage as $coupureMessage) {
  659.                     $template $this->twig->load('mailCoupure.html.twig');
  660.                     if (count($coupuresMessage) == 1) {
  661.                         $objetMail $mailling->getNom();
  662.                     } else {
  663.                         $objetMail $mailling->getNom() .'  '$i '/' count($coupuresMessage);
  664.                     }
  665.                     $debut '';
  666.                     $fin '';
  667.                     if($i == 1){
  668.                         $debut $mailling->getDebutMailCoupure();
  669.                     }
  670.                     if($i == count($coupuresMessage)){
  671.                         $fin $mailling->getFinMailCoupure();
  672.                     }
  673.                     $message = (new \Swift_Message($objetMail))
  674.                         ->setFrom($from)
  675.                         ->setTo($maillingEnCour->getDestinataire())
  676.                         ->setSubject($objetMail)
  677.                         ->setBody($template->render(
  678.                             array('mailling' => $mailling'coupureMessage' => $coupureMessage,
  679.                                 'user' => $mailling->getReplyTo(), 'debut' => $debut'fin' => $fin,
  680.                                 'logo' => $mailling->getClient()->getLogo()->getUrl(), 'idUser' => $maillingEnCour->getUserId(),
  681.                                 'userSend' => $maillingEnCour->getDestinataire())),
  682.                             'text/html')
  683.                         ->setReplyTo($mailling->getReplyTo()->getUser()->getEmail());
  684.                     $message->attachSigner($signer);
  685.                     /** @var PieceJointeMailling $pieceJointe */
  686.                     foreach ($coupureMessage as $pieceJointe) {
  687.                         $message->attach(\Swift_Attachment::fromPath($pathCoupure$pieceJointe->getUrl()));
  688.                     }
  689.                     $i $i 1;
  690.                     $messages[] = $message;
  691.                 }
  692.                 return $messages;
  693.             } else {
  694.                 if (strlen($mailling->getColor())==7){
  695.                     $color $mailling->getColor();
  696.                 } else {
  697.                     $color "#F57E60";
  698.                 }
  699.                 if($mailling->getId()== 5517 or $mailling->getId() == 5899 ){ // template mailling specifique sur demande
  700.                     $template $this->twig->load('mailClient/logoFCA.html.twig');
  701.                 } else {
  702.                     $template $this->twig->load('maillingNew.html.twig');
  703.                 }
  704.                 $message = (new \Swift_Message($mailling->getObjetCour()))
  705.                     ->setFrom($from)
  706.                     ->setTo($maillingEnCour->getDestinataire())
  707.                     ->setSubject($mailling->getObjetCour())
  708.                     ->setBody(
  709.                         $template->render(array('mailling' => $mailling'user' => $mailling->getReplyTo(),
  710.                             'logo' => $mailling->getClient()->getLogo()->getUrl(), 'idUser' => $maillingEnCour->getUserId(),
  711.                             'userSend' => $maillingEnCour->getDestinataire(), 'color' => $color)),
  712.                         'text/html'
  713.                     )
  714.                     ->setReplyTo($mailling->getReplyTo()->getUser()->getEmail());
  715.                 // attache une piece jointe a un mailling spécifique
  716.                 if($mailling->getId() == 6824){
  717.                     $pathfile $this->kernel->getRootDir() . '/../public/Interne/';
  718.                     $message->attach(\Swift_Attachment::fromPath($pathfile'infographie.jpg'));
  719.                 }
  720.                 $message->attachSigner($signer);
  721.             }
  722.         }
  723.         else{
  724.             $message false;
  725.             $maillingEnCour->setErreur('le mail est incorect');
  726.             $this->em->persist($maillingEnCour);
  727.             $this->em->flush();
  728.         }
  729.         return $message;
  730.     }
  731.     public function sendMail(\Swift_Message $message ,\App\Entity\MaillingEnCour $maillingEnCour){
  732.         // Envoi de CP
  733.         if($maillingEnCour->getAdressEnvoie()) {
  734.             $password 'skl001';
  735.             //recuperer derniere adresse de la table
  736.             $derniereAdresseEnvoie $this->em->getRepository('App:DerniereAdresseEnvoie')->findOneBy(['id' => 1]);
  737.             $nomDerniereAdresseEnvoie $derniereAdresseEnvoie->getAdresseEnvoie();
  738.             //recuperer l'id de la derniere adresse envoyee
  739.             $adresseEnvoye $this->em->getRepository('App:CompteurAdressesEnvoi')->findOneBy(['adresse_envoi' => $nomDerniereAdresseEnvoie]);
  740.             $IDadresseEnvoyee $adresseEnvoye->getId();
  741.             //on recup le nb total d'adresses d'envoies
  742.             $totalAdressesEnvoies $this->em->getRepository('App:CompteurAdressesEnvoi')->findAll();
  743.             $nbAdressesEnvoies count($totalAdressesEnvoies);
  744.             //si ID supp au nb total d'adresses on retourne à 1
  745.             if ($IDadresseEnvoyee $nbAdressesEnvoies) {
  746.                 $IDnouvelleAdresse $IDadresseEnvoyee 1;
  747.             } else {
  748.                 $IDnouvelleAdresse 1;
  749.             }
  750.             $nouvelleAdresseEnvoie $this->em->getRepository('App:CompteurAdressesEnvoi')->findOneBy(['id' => $IDnouvelleAdresse]);
  751.             $compteurMail $this->em->getRepository('App:CompteurAdressesEnvoi')
  752.                 ->findOneBy(['adresse_envoi' => $nouvelleAdresseEnvoie->getAdresseEnvoi(), 'date_envoi_mail' => new \DateTime('now')]);
  753.             if (is_null($compteurMail)) {
  754.                 //on ecrase la date
  755.                 $nouvelleAdresseEnvoie->setDateEnvoiMail(new \DateTime('now'));
  756.                 //mettre à jour le compteur d'envoie pour l'adresse
  757.                 $nouvelleAdresseEnvoie->setCompteurMail(1);
  758.             } else {
  759.                 //mettre à jour le compteur d'envoie pour l'adresse
  760.                 $nouvelleAdresseEnvoie->setCompteurMail($nouvelleAdresseEnvoie->getCompteurMail() + 1);
  761.             }
  762.             $derniereAdresseEnvoie->setAdresseEnvoie($nouvelleAdresseEnvoie->getAdresseEnvoi());
  763.             $mail $nouvelleAdresseEnvoie->getAdresseEnvoi();
  764.             $this->em->persist($derniereAdresseEnvoie);
  765.             $this->em->persist($nouvelleAdresseEnvoie);
  766.             $this->em->flush();
  767.             //si c'est un gmail
  768.             if (substr_compare($maillingEnCour->getDestinataire(), "@gmail.com", -1010) === 0) {
  769.                 //recuperer nombre total d'envoi pour l'adresse mail fictive pour date du jour
  770.                 $compteur $this->em->getRepository('App:CompteurAdressesEnvoi')
  771.                     ->findOneBy(['adresse_envoi' => $mail'date_envoi_gmail' => new \DateTime('now')]);
  772.                 if (!is_null($compteur)) {
  773.                     $compteurGmail $compteur->getCompteurGmail();
  774.                 } else {
  775.                     //si aucun compteur pour cette adresse fictive pour la date du jour, écraser l'ancien compteur et changer la date
  776.                     $compteurGmail 0;
  777.                     $compteur $this->em->getRepository('App:CompteurAdressesEnvoi')->findOneBy(['adresse_envoi' => $mail]);
  778.                     $compteur->setCompteurGmail($compteurGmail);
  779.                     $compteur->setDateEnvoiGmail(new \DateTime('now'));
  780.                     $this->em->persist($compteur);
  781.                     $this->em->flush();
  782.                 }
  783.                 //si moins de 500 envois gmail, on garde l'adresse fictive de base
  784.                 if ($compteurGmail 500) {
  785.                     //on ajoute un envoi au compteur
  786.                     $compteur->setCompteurGmail($compteurGmail 1);
  787.                     $this->em->persist($compteur);
  788.                     $this->em->flush();
  789.                 } else {
  790.                     $adressesFictives $this->em->getRepository('App:CompteurAdressesEnvoi')
  791.                         ->findAll();
  792.                     $trouve false;
  793.                     //on parcourt toutes les adresses fictives
  794.                     foreach ($adressesFictives as $adresse) {
  795.                         if ($adresse->getDateEnvoiGmail() < new \DateTime('midnight')) {
  796.                             $adresse->setDateEnvoiGmail(new \DateTime('now'));
  797.                             $adresse->setCompteurGmail(0);
  798.                         }
  799.                         if ($adresse->getCompteurGmail() < 500) {
  800.                             $trouve true;
  801.                             //recuperer l'adresse mail fictive de moins de 500 envois
  802.                             $mail $adresse->getAdresseEnvoi();
  803.                             //On soustrait le compteur $nouvelleAdresseEnvoie si elle est différente de l'adresse envoie courante
  804.                              if ($mail != $nouvelleAdresseEnvoie->getAdresseEnvoi()) {
  805.                                  $nouvelleAdresseEnvoie->setCompteurMail($nouvelleAdresseEnvoie->getCompteurMail() - 1);
  806.                              }
  807.                             $compteurGmail $adresse->getCompteurGmail();
  808.                             $adresse->setCompteurGmail($compteurGmail 1);
  809.                             $this->em->persist($adresse);
  810.                             $this->em->flush();
  811.                             break;
  812.                         }
  813.                     }
  814.                     //dans le cas où il ne reste plus d'adresses fictives à moins de 500 envois gmail
  815.                     if ($trouve === false) {
  816.                         $mail $maillingEnCour->getEnvoyerPar()->getAdresseEnvoi();
  817.                         $cmpt $this->em->getRepository('App:CompteurAdressesEnvoi')->findOneBy(['adresse_envoi' => $mail]);
  818.                         $cmpt->setCompteurGmail($compteurGmail 1);
  819.                         $this->em->persist($cmpt);
  820.                         $this->em->flush();
  821.                     }
  822.                     $this->em->persist($nouvelleAdresseEnvoie);
  823.                     $this->em->flush();
  824.                 }
  825.             }
  826.             // dans le cas d'envoi des retombées
  827.         } else {
  828.             $mail $maillingEnCour->getEnvoyerPar()->getUser()->getEmail();
  829.             $password $maillingEnCour->getEnvoyerPar()->getPasswordMail();
  830.         }
  831.         $transport = new \Swift_SmtpTransport('exchange.escalconsulting.com'587'tls');
  832.         $transport
  833.             ->setUsername($mail)
  834.             ->setPassword($password);
  835.         $mailer = new \Swift_Mailer($transport);
  836.         $logger = new \Swift_Plugins_Loggers_ArrayLogger;
  837.         $mailer->registerPlugin(new \Swift_Plugins_LoggerPlugin($logger));
  838.         // Correspondre l'adresse mail qui se connecte et l'expediteur
  839.         $message->setFrom($mail);
  840.         $mailer->send($message$failRecipient);
  841.         if($failRecipient != []){
  842.             $maillingEnCour->setErreur('erreur lors de l\'envoie du mail');
  843.         } else {
  844.             $maillingEnCour->setEnvoyer(true);
  845.         }
  846.         $this->em->persist($maillingEnCour);
  847.         $this->em->flush();
  848.     }
  849.     public function attachSigner(\Swift_Message $message){
  850.         $pathRSA $this->kernel->getRootDir() . '/../public/Interne/RSA';
  851.         $privateKeyRSA file_get_contents($pathRSA);
  852.         $domainName 'escalconsulting.com';
  853.         $selector '1515841257';
  854.         $signer = new \Swift_Signers_DKIMSigner($privateKeyRSA$domainName$selector);
  855.         $message->attachSigner($signer);
  856.         return $message;
  857.     }
  858.     public function getFrom(\App\Entity\MaillingEnCour $maillingEnCour){
  859.         if($maillingEnCour->getAdressEnvoie()){
  860.             return $maillingEnCour->getEnvoyerPar()->getAdresseEnvoi();
  861.         }
  862.         return $maillingEnCour->getEnvoyerPar()->getUser()->getEmail();
  863.     }
  864.     public function sendMailMerge($randAuthUser $authUser){
  865.         $template $this->twig->load('mergePdf.html.twig');
  866.         $message = (new Swift_Message('pdf'))
  867.             ->setFrom('notification@escalconsulting.com')
  868.             ->setTo($authUser->getUser()->getEmail())
  869.             ->setSubject('pdf')
  870.             ->setBody(
  871.                 $template->render(array('rand'=> $rand)),
  872.                 'text/html'
  873.             )
  874.             ->setReplyTo('notification@escalconsulting.com');
  875.         $mail 'notification@escalconsulting.com';
  876.         $password =  'H76-7Gj%a';
  877.         $transport = new Swift_SmtpTransport('exchange.escalconsulting.com'587'tls');
  878.         $transport
  879.             ->setUsername($mail)
  880.             ->setPassword($password);
  881.         $mailer = new Swift_Mailer($transport);
  882.         $logger = new Swift_Plugins_Loggers_ArrayLogger;
  883.         $mailer->registerPlugin(new Swift_Plugins_LoggerPlugin($logger));
  884.         $mailer->send($message$failRecipient);
  885.     }
  886.     public function sendRappel($rappel){
  887.         $rappel['commentaire'] = str_replace('&#039;''\''$rappel['commentaire']);
  888.         $rappel['titre'] = str_replace('&#039;''\''$rappel['titre']);
  889.         $template $this->twig->load('rappel.html.twig');
  890.         $destinataire $rappel['destinataire'];
  891.         $message = (new \Swift_Message('rappel intranet'))
  892.             ->setFrom('rappel@escalconsulting.com')
  893.             ->setTo($destinataire)
  894.             ->setSubject('rappel intranet')
  895.             ->setBody(
  896.                 $template->render(array('rappel' => $rappel)),
  897.                 'text/html'
  898.             );
  899.         $mail 'rappel@escalconsulting.com';
  900.         $password =  'C?uR*5j59';
  901.         $transport = new Swift_SmtpTransport('exchange.escalconsulting.com'587'tls');
  902.         $transport
  903.             ->setUsername($mail)
  904.             ->setPassword($password);
  905.         $mailer = new Swift_Mailer($transport);
  906.         $logger = new Swift_Plugins_Loggers_ArrayLogger;
  907.         $mailer->registerPlugin(new Swift_Plugins_LoggerPlugin($logger));
  908.         $mailer->send($message$failRecipient);
  909.         dump($failRecipient);
  910.     }
  911.     public function sendDemandeContact($message$object$email$identite$telephone){
  912.         $template $this->twig->load('contact.html.twig');
  913.         $message = (new \Swift_Message('Notification site web'))
  914.             ->setFrom('notification@escalconsulting.com')
  915.             ->setTo('contact@escalconsulting.com')
  916.             ->setSubject(' Demande Site Web /' .$object)
  917.             ->setBody(
  918.                 $template->render(array('identite' => $identite'message' => $message'email' => $email'telephone' => $telephone)),
  919.                 'text/html'
  920.             );
  921.         $mail 'notification@escalconsulting.com';
  922.         $password =  'H76-7Gj%a';
  923.         $transport = new Swift_SmtpTransport('exchange.escalconsulting.com'587'tls');
  924.         $transport
  925.             ->setUsername($mail)
  926.             ->setPassword($password);
  927.         $mailer = new Swift_Mailer($transport);
  928.         $logger = new Swift_Plugins_Loggers_ArrayLogger;
  929.         $mailer->registerPlugin(new Swift_Plugins_LoggerPlugin($logger));
  930.         $mailer->send($message$failRecipient);
  931.     }
  932.     /**
  933.      * @param DemandeDeConge $demandeDeConge
  934.      */
  935.     public function sendMailDemandeCongeResponsable(DemandeDeConge $demandeDeConge$rand$user null){
  936.        $userToSend $this->em->getRepository('App\Entity\User')->findOneBy(['email'=> $demandeDeConge->getPersonneAEnvoyer()]);
  937.         /**  @var  User $userToSend */
  938.        if($userToSend->getEmail() == 'louis@escalconsulting.com'){
  939.            $template $this->twig->load('demandeConge.html.twig');
  940.        } else {
  941.            $template $this->twig->load('demandeCongeResponsable.html.twig');
  942.        }
  943.         $message = (new Swift_Message('demande de congé '$demandeDeConge->getAuthUser()->getUser()->getPrenom()
  944.             . ' ' .$demandeDeConge->getAuthUser()->getUser()->getNom()))
  945.             ->setFrom($demandeDeConge->getAuthUser()->getUser()->getEmail())
  946.             ->setTo($userToSend->getEmail())
  947.             ->setSubject('demande de congé '$demandeDeConge->getAuthUser()->getUser()->getNom() . ' '.
  948.                 $demandeDeConge->getAuthUser()->getUser()->getPrenom())
  949.             ->setBody(
  950.                 $template->render(array('demandeDeConge' => $demandeDeConge'rand'=> $rand'user' => $userToSend'uservalide' => $user)),
  951.                 'text/html'
  952.             )
  953.             ->setReplyTo($demandeDeConge->getAuthUser()->getUser()->getEmail());
  954.         $message->attach(\Swift_Attachment::fromPath($this->kernel->getRootDir() . '/../public/Interne/demandeConge/'.$demandeDeConge->getDebutConge()->format('Y-m-d').'demandeConge'.
  955.             $demandeDeConge->getAuthUser()->getUser()->getNom().'.pdf'));
  956.         $mail $demandeDeConge->getAuthUser()->getUser()->getEmail();
  957.         $password =  $demandeDeConge->getAuthUser()->getPasswordMail();
  958.         $transport = new Swift_SmtpTransport('exchange.escalconsulting.com'587'tls');
  959.         $transport
  960.             ->setUsername($mail)
  961.             ->setPassword($password);
  962.         $mailer = new Swift_Mailer($transport);
  963.         $logger = new Swift_Plugins_Loggers_ArrayLogger;
  964.         $mailer->registerPlugin(new Swift_Plugins_LoggerPlugin($logger));
  965.         $mailer->send($message$failRecipient);
  966.     }
  967.     public function sendReseauxSociaux($coupure){
  968.         // gestion des accents
  969.         $coupure['titre'] = str_replace('&#039;''\''$coupure['titre']);
  970.         $coupure['nom_support'] = str_replace('&#039;''\''$coupure['nom_support']);
  971.         $coupure['doc_lier'] = str_replace('&#039;''\''$coupure['doc_lier']);
  972.         $template $this->twig->load('mailReseauxSociaux.html.twig');
  973.         $destinataire "reseauxsociaux@escalconsulting.com";
  974.         $message = (new \Swift_Message('Information de la coupure'))
  975.             ->setFrom('notification@escalconsulting.com')
  976.             ->setTo($destinataire)
  977.             ->setSubject('Informations coupures')
  978.             ->setBody(
  979.                 $template->render(array('coupure' => $coupure)),
  980.                 'text/html'
  981.             );
  982.         $mail 'notification@escalconsulting.com';
  983.         $password =  'H76-7Gj%a';
  984.         $transport = new Swift_SmtpTransport('exchange.escalconsulting.com'587'tls');
  985.         $transport
  986.             ->setUsername($mail)
  987.             ->setPassword($password);
  988.         $mailer = new Swift_Mailer($transport);
  989.         $logger = new Swift_Plugins_Loggers_ArrayLogger;
  990.         $mailer->registerPlugin(new Swift_Plugins_LoggerPlugin($logger));
  991.         $mailer->send($message$failRecipient);
  992.     }
  993.     public function sendMailNouvelleActualite(Actualite $actualite){
  994.         $template $this->twig->load('mailNouvelleActualite.html.twig');
  995.         $destinataire "paris@escalconsulting.com";
  996.         $message = (new \Swift_Message('Nouvelle Actualité'))
  997.             ->setFrom('notification@escalconsulting.com')
  998.             ->setTo($destinataire)
  999.             ->setSubject('Nouvelle Actualité')
  1000.             ->setBody(
  1001.                 $template->render(array('actualite' => $actualite)),
  1002.                 'text/html'
  1003.             );
  1004.         $mail 'notification@escalconsulting.com';
  1005.         $password =  'H76-7Gj%a';
  1006.         $transport = new Swift_SmtpTransport('exchange.escalconsulting.com'587'tls');
  1007.         $transport
  1008.             ->setUsername($mail)
  1009.             ->setPassword($password);
  1010.         $mailer = new Swift_Mailer($transport);
  1011.         $logger = new Swift_Plugins_Loggers_ArrayLogger;
  1012.         $mailer->registerPlugin(new Swift_Plugins_LoggerPlugin($logger));
  1013.         $mailer->send($message$failRecipient);
  1014.     }
  1015.     public function sendMailMutualisation(Suivi $suivi$axe$interesse$sujet$supports$email){
  1016.         $template $this->twig->load('mailMutualisation.html.twig');
  1017.         $destinataire $email;
  1018.         $message = (new \Swift_Message('Mutualisation'))
  1019.             ->setFrom('notification@escalconsulting.com')
  1020.             ->setTo($destinataire)
  1021.             ->addCc('mutualisation@escalconsulting.com')
  1022.             ->setSubject('Mutualisation')
  1023.             ->setBody(
  1024.                 $template->render(array('suivi' => $suivi'axe'=> $axe'interesse' => $interesse'sujet' => $sujet'supports' => $supports)),
  1025.                 'text/html'
  1026.             );
  1027.         $mail 'notification@escalconsulting.com';
  1028.         $password =  'H76-7Gj%a';
  1029.         $transport = new Swift_SmtpTransport('exchange.escalconsulting.com'587'tls');
  1030.         $transport
  1031.             ->setUsername($mail)
  1032.             ->setPassword($password);
  1033.         $mailer = new Swift_Mailer($transport);
  1034.         $logger = new Swift_Plugins_Loggers_ArrayLogger;
  1035.         $mailer->registerPlugin(new Swift_Plugins_LoggerPlugin($logger));
  1036.         $mailer->send($message$failRecipient);
  1037.     }
  1038.     public function sendDesabonnement($email){
  1039.         $template $this->twig->load('notificationDesabonnement.html.twig');
  1040.         $destinataire $email;
  1041.         $message = (new \Swift_Message('Confirmation de désabonnement'))
  1042.             ->setFrom('notification@escalconsulting.com')
  1043.             ->setTo($destinataire)
  1044.             ->setSubject('Confirmation de désabonnement')
  1045.             ->setBody(
  1046.                 $template->render(array('email' => $email)),
  1047.                 'text/html'
  1048.             );
  1049.         $mail 'notification@escalconsulting.com';
  1050.         $password =  'H76-7Gj%a';
  1051.         $transport = new Swift_SmtpTransport('exchange.escalconsulting.com'587'tls');
  1052.         $transport
  1053.             ->setUsername($mail)
  1054.             ->setPassword($password);
  1055.         $mailer = new Swift_Mailer($transport);
  1056.         $logger = new Swift_Plugins_Loggers_ArrayLogger;
  1057.         $mailer->registerPlugin(new Swift_Plugins_LoggerPlugin($logger));
  1058.         $mailer->send($message$failRecipient);
  1059.     }
  1060.     public function sendDemandeITSupprimerContact($contactID$nomContact$nomDemandeur) {
  1061.         // Gestion des accents
  1062.         $nomDemandeur str_replace('&#039;''\'',$nomDemandeur);
  1063.         $nomContact str_replace('&#039;''\'',$nomContact);
  1064.         $template $this->twig->load('demandeSuppressionContact.html.twig');
  1065.         $destinataire 'informatique@escalconsulting.com';
  1066.         $message = (new \Swift_Message("Demande de suppression d'un Contact"))
  1067.             ->setFrom('notification@escalconsulting.com')
  1068.             ->setTo($destinataire)
  1069.             ->setSubject("Demande de suppression d'un Contact")
  1070.             ->setBody(
  1071.                 $template->render(array('id' => $contactID ,'contact' => $nomContact'demandeur' => $nomDemandeur)),
  1072.                 'text/html'
  1073.             );
  1074.         $mail 'notification@escalconsulting.com';
  1075.         $password =  'H76-7Gj%a';
  1076.         $transport = new Swift_SmtpTransport('exchange.escalconsulting.com'587'tls');
  1077.         $transport
  1078.             ->setUsername($mail)
  1079.             ->setPassword($password);
  1080.         $mailer = new Swift_Mailer($transport);
  1081.         $logger = new Swift_Plugins_Loggers_ArrayLogger;
  1082.         $mailer->registerPlugin(new Swift_Plugins_LoggerPlugin($logger));
  1083.         $mailer->send($message$failRecipient);
  1084.     }
  1085.     public function sendDemandeEnvoyerIT($suggestion) {
  1086.         $template $this->twig->load('suggestionAmelioration.html.twig');
  1087.         $destinataire 'bdd@escalconsulting.com';
  1088.         $message = (new \Swift_Message("Suggestions d'amélioration - Escalnet"))
  1089.             ->setFrom('notification@escalconsulting.com')
  1090.             ->setTo($destinataire)
  1091.             ->setSubject("Suggestions d'amélioration - Escalnet")
  1092.             ->setBody(
  1093.                 $template->render(array('suggestion' => $suggestion)),
  1094.                 'text/html'
  1095.             );
  1096.         $mail 'notification@escalconsulting.com';
  1097.         $password =  'H76-7Gj%a';
  1098.         $transport = new Swift_SmtpTransport('exchange.escalconsulting.com'587'tls');
  1099.         $transport
  1100.             ->setUsername($mail)
  1101.             ->setPassword($password);
  1102.         $mailer = new Swift_Mailer($transport);
  1103.         $logger = new Swift_Plugins_Loggers_ArrayLogger;
  1104.         $mailer->registerPlugin(new Swift_Plugins_LoggerPlugin($logger));
  1105.         $mailer->send($message$failRecipient);
  1106.     }
  1107. }