Skip to content

Commit

Permalink
Merge pull request #9561 from nextcloud/fix/close-smtp-connection
Browse files Browse the repository at this point in the history
fix: close smtp connection after sending or on error
  • Loading branch information
st3iny authored Jun 25, 2024
2 parents f2a05d0 + 8f9a89b commit 3b879b4
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/Service/MailTransmission.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 3b879b4

Please sign in to comment.