16
16
use Symfony \Component \Mailer \Transport \Smtp \EsmtpTransport ;
17
17
use Symfony \Component \Mailer \Transport \Smtp \Auth \LoginAuthenticator ;
18
18
use Symfony \Component \Mailer \Transport \Smtp \Auth \PlainAuthenticator ;
19
+ use Symfony \Component \Mailer \Transport \Smtp \EsmtpTransportFactory ;
19
20
use Magento \Framework \App \Config \ScopeConfigInterface ;
20
21
use Magento \Framework \App \ObjectManager ;
21
22
use Magento \Framework \Exception \MailException ;
@@ -78,6 +79,11 @@ class Transport implements TransportInterface
78
79
*/
79
80
private const XML_PATH_SSL = 'system/smtp/ssl ' ;
80
81
82
+ /**
83
+ * SMTP scheme constant
84
+ */
85
+ private const SMTP_SCHEME = 'smtp ' ;
86
+
81
87
/**
82
88
* Whether return path should be set or no.
83
89
*
@@ -146,7 +152,7 @@ public function __construct(
146
152
public function getTransport (): SymfonyTransportInterface
147
153
{
148
154
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 );
150
156
if ($ transportType === 'smtp ' ) {
151
157
$ this ->symfonyTransport = $ this ->createSmtpTransport ();
152
158
} else {
@@ -170,19 +176,27 @@ private function createSmtpTransport(): SymfonyTransportInterface
170
176
$ password = $ this ->scopeConfig ->getValue (self ::XML_PATH_PASSWORD , ScopeInterface::SCOPE_STORE );
171
177
$ auth = $ this ->scopeConfig ->getValue (self ::XML_PATH_AUTH , ScopeInterface::SCOPE_STORE );
172
178
$ ssl = $ this ->scopeConfig ->getValue (self ::XML_PATH_SSL , ScopeInterface::SCOPE_STORE );
173
- $ tls = false ;
174
179
180
+ $ options = [];
175
181
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 ;
177
187
}
178
188
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 );
186
200
187
201
switch ($ auth ) {
188
202
case 'plain ' :
0 commit comments