diff --git a/lib/Service/MailTransmission.php b/lib/Service/MailTransmission.php index 2ce080a17a..c06211789f 100644 --- a/lib/Service/MailTransmission.php +++ b/lib/Service/MailTransmission.php @@ -15,6 +15,7 @@ use Horde_Imap_Client_Fetch_Query; use Horde_Imap_Client_Ids; use Horde_Mail_Transport_Null; +use Horde_Mail_Transport_Smtphorde; use Horde_Mime_Exception; use Horde_Mime_Headers; use Horde_Mime_Headers_Addresses; @@ -151,6 +152,14 @@ public function sendMessage(Account $account, LocalMessage $localMessage): void } $localMessage->setStatus(LocalMessage::STATUS_ERROR); return; + } finally { + if ($transport instanceof Horde_Mail_Transport_Smtphorde) { + try { + $transport->getSMTPObject()->logout(); + } catch (\Throwable $e) { + // Handle silently as this is a resource usage optimization + } + } } $this->eventDispatcher->dispatchTyped(