Skip to content

Commit

Permalink
smtp: Only init SMTP if we have credentials
Browse files Browse the repository at this point in the history
  • Loading branch information
protich committed Nov 13, 2022
1 parent de620fe commit c19a5f0
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions include/class.email.php
Expand Up @@ -1261,13 +1261,15 @@ public function getSmtpConnection() {
public function getSmtp(osTicket\Mail\AuthCredentials $cred=null) {
if (!isset($this->smtp) || $cred) {
$this->cred = $cred ?: $this->getFreshCredentials();
$setting = $this->getAccountSetting();
$setting->setCredentials($this->cred);
$smtpOptions = new osTicket\Mail\SmtpOptions($setting);
$smtp = new osTicket\Mail\Smtp($smtpOptions);
// Attempt to connect if Credentials are sent
if ($cred) $smtp->connect();
$this->smtp = $smtp;
if ($this->cred) {
$setting = $this->getAccountSetting();
$setting->setCredentials($this->cred);
$smtpOptions = new osTicket\Mail\SmtpOptions($setting);
$smtp = new osTicket\Mail\Smtp($smtpOptions);
// Attempt to connect now if credentials are sent in
if ($cred) $smtp->connect();
$this->smtp = $smtp;
}
}
return $this->smtp;
}
Expand Down

0 comments on commit c19a5f0

Please sign in to comment.