Loading config/unicaen-mail.local.php.dist +49 −6 Original line number Diff line number Diff line Loading @@ -20,17 +20,60 @@ return [ 'host' => 'XXX.XXX.XX', 'port' => 'XX', ], /** * Adresses des redirection si do_not_send est à true * Configuration locale du module UnicaenApp. * * If you have a ./config/autoload/ directory set up for your project, * drop this config file in it and change the values as you wish. */ 'redirect_to' => ['XXX@XXX.XX', ], 'do_not_send' => true, use UnicaenMail\Entity\Db\Mail; return [ 'unicaen-mail' => [ /** * Classe de entité **/ 'mail_entity_class' => Mail::class, /** * Configuration de l'expéditeur * Options concernant l'envoi de mail par l'application */ 'transport_options' => [ 'host' => 'smtp.unicaen.fr', 'port' => 25, ], /** * Adresses des redirections si do_not_send est à true */ 'module' => [ 'default' => [ 'redirect_to' => ['XXX@XXX.XX',], 'do_not_send' => true, 'subject_prefix' => 'XXX', 'from_name' => 'XXX : XXXX XX XXXXXXX', 'from_email' => 'ne-pas-repondre@XXXX.XX' 'from_name' => 'XXX | XXXXX', 'from_email' => 'XXX@XXX.XX', ], /** On peut ajouter un clef de module pour la référencer dans la méthode sendMail afin d'exploiter les données passée en valeur. */ // 'MonPetitModule' => [ // 'redirect_to' => ['XXX@XXX.XX',], // 'do_not_send' => true, // 'subject_prefix' => 'Mes petit module', // 'from_name' => 'mon-ptit-module', // 'from_email' => 'assistance.mon-petit-module@XXX.XX', // ] ] ], 'server_url' => 'http://emc2.unicaen.fr', // 'service_manager' => [ // 'delegators' => [ // TreeRouteStack::class => [ // TreeRouteStackConsoleDelegatorFactory::class, // ], // ] // ], ]; src/UnicaenMail/Service/Mail/MailService.php +15 −8 Original line number Diff line number Diff line Loading @@ -24,6 +24,7 @@ class MailService { use ProvidesObjectManager; private ?string $entityClass = null; private array $config = []; /** * @param string $entityClass Loading @@ -35,6 +36,11 @@ class MailService { return $this; } public function setConfig(array $config) : void { $this->config = $config; } public function createMailEntity() : Object { $entity = new $this->entityClass(); Loading Loading @@ -174,10 +180,11 @@ class MailService { * @param $to * @param $subject * @param $texte * @param string $module * @param null $attachement_path * @return Mail */ public function sendMail($to, $subject, $texte, $attachement_path = null) : Mail public function sendMail($to, $subject, $texte, ?string $module = null, $attachement_path = null) : Mail { if (is_string($to)) $to=explode(',', $to); if (!is_array($to)) $to = [$to]; Loading @@ -197,26 +204,25 @@ class MailService { } $mail->setSujet($subject); $fromEmail = ($module)?$this->config['module'][$module]['from_email']:$this->config['default']['from_email']; $fromName = ($module)?$this->config['module'][$module]['from_name']:$this->config['default']['from_name']; $doNotSend = ($module)?$this->config['module'][$module]['do_not_send']:$this->config['default']['do_not_send']; $sujet = '['.$this->subjectPrefix.'] ' . $subject; if ($this->doNotSend) { if ($doNotSend) { $sujet .= ' {REDIR}'; } // echo substr($subject, 88) ." : ini=".count($initialTo) . "/ cur=". count($to)."\n"; // foreach ($initialTo as $item) echo $item . "\n"; // echo "\n"; $message = (new Message())->setEncoding('UTF-8'); $message->setFrom($this->fromEmail, $this->fromName); $message->setFrom($fromEmail, $fromName); $message->setTo($to); $message->setSubject($sujet); $texte = "<p><i>Ce courrier électronique vous a été adressé <strong>automatiquement</strong> par l'application ".$this->subjectPrefix.". </i></p>" . $texte; $mail->setCorps($texte); $this->create($mail); if ($this->doNotSend) { if ($doNotSend) { $texte .= "<br/><br/><hr/><br/>"; $texte .= "Initialement envoyé à :"; $texte .= "<ul>"; Loading Loading @@ -248,6 +254,7 @@ class MailService { $body->setParts($parts); $message->setBody($body); die(); $this->transport->send($message); $mail->setStatusEnvoi(Mail::SUCCESS); Loading src/UnicaenMail/Service/Mail/MailServiceFactory.php +1 −0 Original line number Diff line number Diff line Loading @@ -31,6 +31,7 @@ class MailServiceFactory { $config['redirect_to'], $config['do_not_send'], $config['from_name'], $config['from_email'], $config['subject_prefix'] ); $service->setConfig($config); $service->setEntityClass($config['mail_entity_class']); $service->setObjectManager($entityManager); return $service; Loading Loading
config/unicaen-mail.local.php.dist +49 −6 Original line number Diff line number Diff line Loading @@ -20,17 +20,60 @@ return [ 'host' => 'XXX.XXX.XX', 'port' => 'XX', ], /** * Adresses des redirection si do_not_send est à true * Configuration locale du module UnicaenApp. * * If you have a ./config/autoload/ directory set up for your project, * drop this config file in it and change the values as you wish. */ 'redirect_to' => ['XXX@XXX.XX', ], 'do_not_send' => true, use UnicaenMail\Entity\Db\Mail; return [ 'unicaen-mail' => [ /** * Classe de entité **/ 'mail_entity_class' => Mail::class, /** * Configuration de l'expéditeur * Options concernant l'envoi de mail par l'application */ 'transport_options' => [ 'host' => 'smtp.unicaen.fr', 'port' => 25, ], /** * Adresses des redirections si do_not_send est à true */ 'module' => [ 'default' => [ 'redirect_to' => ['XXX@XXX.XX',], 'do_not_send' => true, 'subject_prefix' => 'XXX', 'from_name' => 'XXX : XXXX XX XXXXXXX', 'from_email' => 'ne-pas-repondre@XXXX.XX' 'from_name' => 'XXX | XXXXX', 'from_email' => 'XXX@XXX.XX', ], /** On peut ajouter un clef de module pour la référencer dans la méthode sendMail afin d'exploiter les données passée en valeur. */ // 'MonPetitModule' => [ // 'redirect_to' => ['XXX@XXX.XX',], // 'do_not_send' => true, // 'subject_prefix' => 'Mes petit module', // 'from_name' => 'mon-ptit-module', // 'from_email' => 'assistance.mon-petit-module@XXX.XX', // ] ] ], 'server_url' => 'http://emc2.unicaen.fr', // 'service_manager' => [ // 'delegators' => [ // TreeRouteStack::class => [ // TreeRouteStackConsoleDelegatorFactory::class, // ], // ] // ], ];
src/UnicaenMail/Service/Mail/MailService.php +15 −8 Original line number Diff line number Diff line Loading @@ -24,6 +24,7 @@ class MailService { use ProvidesObjectManager; private ?string $entityClass = null; private array $config = []; /** * @param string $entityClass Loading @@ -35,6 +36,11 @@ class MailService { return $this; } public function setConfig(array $config) : void { $this->config = $config; } public function createMailEntity() : Object { $entity = new $this->entityClass(); Loading Loading @@ -174,10 +180,11 @@ class MailService { * @param $to * @param $subject * @param $texte * @param string $module * @param null $attachement_path * @return Mail */ public function sendMail($to, $subject, $texte, $attachement_path = null) : Mail public function sendMail($to, $subject, $texte, ?string $module = null, $attachement_path = null) : Mail { if (is_string($to)) $to=explode(',', $to); if (!is_array($to)) $to = [$to]; Loading @@ -197,26 +204,25 @@ class MailService { } $mail->setSujet($subject); $fromEmail = ($module)?$this->config['module'][$module]['from_email']:$this->config['default']['from_email']; $fromName = ($module)?$this->config['module'][$module]['from_name']:$this->config['default']['from_name']; $doNotSend = ($module)?$this->config['module'][$module]['do_not_send']:$this->config['default']['do_not_send']; $sujet = '['.$this->subjectPrefix.'] ' . $subject; if ($this->doNotSend) { if ($doNotSend) { $sujet .= ' {REDIR}'; } // echo substr($subject, 88) ." : ini=".count($initialTo) . "/ cur=". count($to)."\n"; // foreach ($initialTo as $item) echo $item . "\n"; // echo "\n"; $message = (new Message())->setEncoding('UTF-8'); $message->setFrom($this->fromEmail, $this->fromName); $message->setFrom($fromEmail, $fromName); $message->setTo($to); $message->setSubject($sujet); $texte = "<p><i>Ce courrier électronique vous a été adressé <strong>automatiquement</strong> par l'application ".$this->subjectPrefix.". </i></p>" . $texte; $mail->setCorps($texte); $this->create($mail); if ($this->doNotSend) { if ($doNotSend) { $texte .= "<br/><br/><hr/><br/>"; $texte .= "Initialement envoyé à :"; $texte .= "<ul>"; Loading Loading @@ -248,6 +254,7 @@ class MailService { $body->setParts($parts); $message->setBody($body); die(); $this->transport->send($message); $mail->setStatusEnvoi(Mail::SUCCESS); Loading
src/UnicaenMail/Service/Mail/MailServiceFactory.php +1 −0 Original line number Diff line number Diff line Loading @@ -31,6 +31,7 @@ class MailServiceFactory { $config['redirect_to'], $config['do_not_send'], $config['from_name'], $config['from_email'], $config['subject_prefix'] ); $service->setConfig($config); $service->setEntityClass($config['mail_entity_class']); $service->setObjectManager($entityManager); return $service; Loading