[TikiWiki-commits] [Git][tikiwiki/tiki][28.x] [BP][FIX] Failed sending mail with no recipients

"ushindi bienvenu \(@usbbush\) via TikiWiki-cvs" <[email protected]>
Newsgroups gmane.comp.cms.tiki.cvs
Message-ID <68a7c193ce8bc_2c107df418417@gitlab-sidekiq-low-urgency-cpu-bound-v2-5f6d84f9cc-b79st.mail>

ushindi bienvenu pushed to branch 28.x at Tiki Wiki CMS Groupware / Tiki


Commits:
9bfc94d6 by ushindi bienvenu at 2025-08-22T00:55:34+00:00
[BP][FIX] Failed sending mail with no recipients
---
* [FIX] Failed sending mail with no recipients
---
* [FIX] Failed sending mail with no recipients
---
* [FIX] Failed sending mail with no recipients

See merge request tikiwiki/tiki!8316

See merge request tikiwiki/tiki!8354

See merge request tikiwiki/tiki!8360

- - - - -


1 changed file:

- lib/core/Tiki/Command/MailQueueSendCommand.php


Changes:

=====================================
lib/core/Tiki/Command/MailQueueSendCommand.php
=====================================
@@ -38,32 +38,36 @@ class MailQueueSendCommand extends Command
             $error = '';
 
             if ($mail && (get_class($mail) === 'Laminas\Mail\Message' || get_class($mail) === 'Zend\Mail\Message')) {
-                try {
-                    tiki_send_email($mail);
-                    $title = 'mail';
-                } catch (ZendMailException | SlmMailException $e) {
-                    $title = 'mail error';
-                    $error = $e->getMessage();
-                }
-
-                if ($error || $prefs['log_mail'] == 'y') {
-                    foreach ($mail->getTo() as $destination) {
-                        $logslib->add_log($title, $error . "\n " . $destination->getEmail() . '/' . $mail->getSubject());
-                    }
-                    foreach ($mail->getCc() as $destination) {
-                        $logslib->add_log($title, $error . "\n " . $destination->getEmail() . '/' . $mail->getSubject());
+                $query = 'DELETE FROM tiki_mail_queue WHERE messageId = ?';
+                if (empty($this->collectRecipients($mail))) {
+                    $output->writeln('Deleted object id: ' . $message['messageId'] . ' (mail has no recipients)');
+                } else {
+                    try {
+                        tiki_send_email($mail);
+                        $title = 'mail';
+                    } catch (ZendMailException | SlmMailException $e) {
+                        $title = 'mail error';
+                        $error = $e->getMessage();
                     }
-                    foreach ($mail->getBcc() as $destination) {
-                        $logslib->add_log($title, $error . "\n " . $destination->getEmail() . '/' . $mail->getSubject());
+
+                    if ($error || $prefs['log_mail'] == 'y') {
+                        foreach ($mail->getTo() as $destination) {
+                            $logslib->add_log($title, $error . "\n " . $destination->getEmail() . '/' . $mail->getSubject());
+                        }
+                        foreach ($mail->getCc() as $destination) {
+                            $logslib->add_log($title, $error . "\n " . $destination->getEmail() . '/' . $mail->getSubject());
+                        }
+                        foreach ($mail->getBcc() as $destination) {
+                            $logslib->add_log($title, $error . "\n " . $destination->getEmail() . '/' . $mail->getSubject());
+                        }
                     }
-                }
 
-                if ($error) {
-                    $query = 'UPDATE tiki_mail_queue SET attempts = attempts + 1 WHERE messageId = ?';
-                    $output->writeln('Failed sending mail object id: ' . $message['messageId'] . ' (' . $error . ')');
-                } else {
-                    $query = 'DELETE FROM tiki_mail_queue WHERE messageId = ?';
-                    $output->writeln('Sent.');
+                    if ($error) {
+                        $query = 'UPDATE tiki_mail_queue SET attempts = attempts + 1 WHERE messageId = ?';
+                        $output->writeln('Failed sending mail object id: ' . $message['messageId'] . ' (' . $error . ')');
+                    } else {
+                        $output->writeln('Sent.');
+                    }
                 }
 
                 \TikiDb::get()->query($query, [$message['messageId']]);
@@ -74,4 +78,19 @@ class MailQueueSendCommand extends Command
         $output->writeln('Mail queue processed...');
         return Command::SUCCESS;
     }
+
+    private function collectRecipients($mail)
+    {
+        $recipients = [];
+        foreach ($mail->getTo() as $destination) {
+            $recipients[] = $destination->getEmail();
+        }
+        foreach ($mail->getCc() as $destination) {
+            $recipients[] = $destination->getEmail();
+        }
+        foreach ($mail->getBcc() as $destination) {
+            $recipients[] = $destination->getEmail();
+        }
+        return $recipients;
+    }
 }



View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/9bfc94d6801dfceadd6636b14ed86a04b5b91191

-- 
View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/9bfc94d6801dfceadd6636b14ed86a04b5b91191
You're receiving this email because of your account on gitlab.com.

_______________________________________________
TikiWiki-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tikiwiki-cvs
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.