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