Skip to content

Commit

Permalink
Merge pull request #7656 from nextcloud/backport/7652/stable1.14
Browse files Browse the repository at this point in the history
[stable1.14] Fix XOAUTH2 auth via SMTP
  • Loading branch information
ChristophWurst authored Dec 21, 2022
2 parents 317aa37 + f794fa4 commit 3593287
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions lib/SMTP/SmtpClientFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
use Horde_Mail_Transport;
use Horde_Mail_Transport_Mail;
use Horde_Mail_Transport_Smtphorde;
use Horde_Smtp_Password_Xoauth2;
use OCA\Mail\Account;
use OCA\Mail\Support\HostNameFactory;
use OCP\IConfig;
Expand Down Expand Up @@ -65,13 +66,12 @@ public function create(Account $account): Horde_Mail_Transport {
return new Horde_Mail_Transport_Mail();
}

$password = $mailAccount->getOutboundPassword();
$password = $this->crypto->decrypt($password);
$decryptedPassword = $this->crypto->decrypt($mailAccount->getOutboundPassword());
$security = $mailAccount->getOutboundSslMode();
$params = [
'localhost' => $this->hostNameFactory->getHostName(),
'host' => $mailAccount->getOutboundHost(),
'password' => $password,
'password' => $decryptedPassword,
'port' => $mailAccount->getOutboundPort(),
'username' => $mailAccount->getOutboundUser(),
'secure' => $security === 'none' ? false : $security,
Expand All @@ -83,6 +83,12 @@ public function create(Account $account): Horde_Mail_Transport {
],
],
];
if ($account->getMailAccount()->getAuthMethod() === 'xoauth2') {
$params['xoauth2_token'] = new Horde_Smtp_Password_Xoauth2(
$account->getEmail(),
$decryptedPassword,
);
}
if ($this->config->getSystemValue('debug', false)) {
$params['debug'] = $this->config->getSystemValue('datadirectory') . '/horde_smtp.log';
}
Expand Down

0 comments on commit 3593287

Please sign in to comment.