1616use Symfony \Component \Mailer \Transport \Smtp \EsmtpTransport ;
1717use Symfony \Component \Mailer \Transport \Smtp \Auth \LoginAuthenticator ;
1818use Symfony \Component \Mailer \Transport \Smtp \Auth \PlainAuthenticator ;
19+ use Symfony \Component \Mailer \Transport \Smtp \EsmtpTransportFactory ;
1920use Magento \Framework \App \Config \ScopeConfigInterface ;
2021use Magento \Framework \App \ObjectManager ;
2122use Magento \Framework \Exception \MailException ;
@@ -78,6 +79,11 @@ class Transport implements TransportInterface
7879 */
7980 private const XML_PATH_SSL = 'system/smtp/ssl ' ;
8081
82+ /**
83+ * SMTP scheme constant
84+ */
85+ private const SMTP_SCHEME = 'smtp ' ;
86+
8187 /**
8288 * Whether return path should be set or no.
8389 *
@@ -146,7 +152,7 @@ public function __construct(
146152 public function getTransport (): SymfonyTransportInterface
147153 {
148154 if (!isset ($ this ->symfonyTransport )) {
149- $ transportType = $ this ->scopeConfig ->getValue (self ::XML_PATH_TRANSPORT );
155+ $ transportType = $ this ->scopeConfig ->getValue (self ::XML_PATH_TRANSPORT , ScopeInterface:: SCOPE_STORE );
150156 if ($ transportType === 'smtp ' ) {
151157 $ this ->symfonyTransport = $ this ->createSmtpTransport ();
152158 } else {
@@ -170,19 +176,27 @@ private function createSmtpTransport(): SymfonyTransportInterface
170176 $ password = $ this ->scopeConfig ->getValue (self ::XML_PATH_PASSWORD , ScopeInterface::SCOPE_STORE );
171177 $ auth = $ this ->scopeConfig ->getValue (self ::XML_PATH_AUTH , ScopeInterface::SCOPE_STORE );
172178 $ ssl = $ this ->scopeConfig ->getValue (self ::XML_PATH_SSL , ScopeInterface::SCOPE_STORE );
173- $ tls = false ;
174179
180+ $ options = [];
175181 if ($ ssl === 'tls ' ) {
176- $ tls = true ;
182+ $ options ['tls ' ] = true ;
183+ } elseif ($ ssl === 'ssl ' ) {
184+ $ options ['ssl ' ] = true ;
185+ $ options ['verify_peer ' ] = true ;
186+ $ options ['verify_peer_name ' ] = true ;
177187 }
178188
179- $ transport = new EsmtpTransport ($ host , $ port , $ tls );
180- if ($ username ) {
181- $ transport ->setUsername ($ username );
182- }
183- if ($ password ) {
184- $ transport ->setPassword ($ password );
185- }
189+ $ dsn = new Dsn (
190+ self ::SMTP_SCHEME ,
191+ $ host ,
192+ $ username ,
193+ $ password ,
194+ $ port ,
195+ $ options
196+ );
197+
198+ $ factory = new EsmtpTransportFactory ();
199+ $ transport = $ factory ->create ($ dsn );
186200
187201 switch ($ auth ) {
188202 case 'plain ' :
0 commit comments