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