Skip to content

Commit

Permalink
fix: close smtp connection after sending or on error
Browse files Browse the repository at this point in the history
Unfortunately, `getSMTPObject()` creates a connection if it's not
already established. Ideally, the connection is already established due
to the send command some lines above so we only close it. There is no
way around it because the wrapped SMTP object is private.

Signed-off-by: Richard Steinmetz <[email protected]>
  • Loading branch information
st3iny committed Apr 12, 2024
1 parent 53d2517 commit 665facd
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/SMTP/SmtpClientFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function __construct(IConfig $config,
*
* @return Horde_Mail_Transport
*/
public function create(Account $account): Horde_Mail_Transport {
public function create(Account $account): Horde_Mail_Transport_Smtphorde {
$mailAccount = $account->getMailAccount();
$transport = $this->config->getSystemValue('app.mail.transport', 'smtp');
if ($transport === 'php-mail') {
Expand Down
2 changes: 2 additions & 0 deletions lib/Service/MailTransmission.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ public function sendMessage(Account $account, LocalMessage $localMessage): void
$localMessage->setStatus(LocalMessage::STATUS_SMPT_SEND_FAIL);
$this->logger->error($e->getMessage(), ['exception' => $e]);
return;
} finally {
$transport->getSMTPObject()->logout();
}

$this->eventDispatcher->dispatchTyped(
Expand Down

0 comments on commit 665facd

Please sign in to comment.