src/Ovh/OvhSend.php line 1051

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