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