Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix XOAUTH2 auth via SMTP #7645

Merged
merged 1 commit into from
Nov 22, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions lib/SMTP/SmtpClientFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

namespace OCA\Mail\SMTP;

use Horde_Imap_Client_Password_Xoauth2;
use Horde_Mail_Transport;
use Horde_Mail_Transport_Mail;
use Horde_Mail_Transport_Smtphorde;
Expand Down Expand Up @@ -64,13 +65,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 @@ -82,6 +82,12 @@ public function create(Account $account): Horde_Mail_Transport {
],
],
];
if ($account->getMailAccount()->getAuthMethod() === 'xoauth2') {
$params['xoauth2_token'] = new Horde_Imap_Client_Password_Xoauth2(
$account->getEmail(),
$decryptedPassword,
);
}
if ($this->config->getSystemValue('debug', false)) {
$params['debug'] = $this->config->getSystemValue('datadirectory') . '/horde_smtp.log';
}
Expand Down