Skip to content
Closed
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
30 changes: 29 additions & 1 deletion Mail/Rse/Mail.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
use Laminas\Mail\Transport\Smtp;
use Laminas\Mail\Transport\SmtpOptions;
use Symfony\Component\Mailer\Transport\Smtp\EsmtpTransport;
use Symfony\Component\Mailer\Transport\Smtp\EsmtpTransportFactory;
use Symfony\Component\Mailer\Transport\Dsn;
use Symfony\Component\Mime\Parser\MessageParser;
use Zend_Exception;

Expand All @@ -35,6 +37,11 @@
*/
class Mail
{
/**
* SMTP scheme constant
*/
private const SMTP_SCHEME = 'smtp';

/**
* @var Data
*/
Expand Down Expand Up @@ -282,7 +289,28 @@ public function getSymfonyTransport($storeId)
$encryption = $config['protocol'] ?? null;
$username = $config['username'] ?? null;
$password = $this->smtpHelper->getPassword($storeId);
$transport = new EsmtpTransport($host, $port, $encryption);

$options = [];
if ($encryption === 'tls') {
$tls = true;
$options['tls'] = true;
} elseif ($encryption === 'ssl') {
$options['ssl'] = true;
$options['verify_peer'] = true;
$options['verify_peer_name'] = true;
}

$dsn = new Dsn(
self::SMTP_SCHEME,
$host,
$username,
$password,
$port,
$options
);
$factory = new EsmtpTransportFactory();
$transport = $factory->create($dsn);

if ($username && $password) {
$transport->setUsername($username);
$transport->setPassword($password);
Expand Down