Closed dmitry-kulikov closed 6 years ago
// you have to setup these variables $host = ''; $username = ''; $password = ''; $port = ''; $recipient = ''; $transport = [ 'class' => 'Swift_SmtpTransport', 'encryption' => 'tls', 'host' => $host, 'username' => $username, 'password' => $password, 'port' => $port, ]; $message = (new \yii\swiftmailer\Message()) ->setFrom('example@example.com') ->setTo($recipient) ->setSubject('Test') ->setTextBody('Hello world!'); Yii::$app->mailer->setTransport($transport); Yii::$app->mailer->send($message); $transport['password'] = null; // wrong password, we expect Swift_TransportException Yii::$app->mailer->setTransport($transport); Yii::$app->mailer->send($message);
Message successfully sent for the first time, the second time - Swift_TransportException.
Message sent successfully twice.
setTransport has no effect on further emails sending because Swift_Mailer object is cached after first call of getSwiftMailer https://github.com/yiisoft/yii2-swiftmailer/blob/0d5ad79a6debe5fbb753c2ce4a89a7139e4acfe6/src/Mailer.php#L105-L112 While it can be workarounded, I think current behavior is unexpected.
setTransport
getSwiftMailer
What steps will reproduce the problem?
What's expected?
Message successfully sent for the first time, the second time - Swift_TransportException.
What do you get instead?
Message sent successfully twice.
Additional info
setTransport
has no effect on further emails sending because Swift_Mailer object is cached after first call ofgetSwiftMailer
https://github.com/yiisoft/yii2-swiftmailer/blob/0d5ad79a6debe5fbb753c2ce4a89a7139e4acfe6/src/Mailer.php#L105-L112 While it can be workarounded, I think current behavior is unexpected.