getOrganizationDeletionRequest(); try { $this->organizationFactory->delete($organizationCreationRequest); $this->sendMail( $organizationCreationRequest->getSendConfirmationEmailAt() ?? $this->opentalentMailReport, 'Organization deleted', 'The organization n° '.$organizationCreationRequest->getOrganizationId().' has been deleted successfully.', ); } catch (\Exception $e) { $this->sendMail( $organizationCreationRequest->getSendConfirmationEmailAt() ?? $this->opentalentMailReport, 'Organization deletion : an error occurred', 'An error occurred while deleting the new organization : \n'.$e->getMessage() ); throw $e; } } /** * @throws TransportExceptionInterface */ private function sendMail( string $to, string $subject, string $content, ): void { $symfonyMail = (new SymfonyEmail()) ->from($this->opentalentMailReport) ->replyTo($this->opentalentMailReport) ->returnPath(Address::create($this->opentalentMailReport)) ->to($to) ->subject($subject) ->text($content); $this->symfonyMailer->send($symfonyMail); } }