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