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