Override Yii2 Swiftmailer Recipient -
i need override recipient email every instance of swiftmailer's send() function throughout yii2 application. purpose of load testing.
is there easy way this? or @ least way without editing swiftmailer's vendor files?
if test why not set usefiletransport emails saved in folder of choice instead of being sent. configure this:
'components' => [ // ... 'mailer' => [ 'class' => 'yii\swiftmailer\mailer', 'usefiletransport' => true, ], ], this save emails in @runtime/mail folder, if want different 1 set:
'mailer' => [ // ... 'filetransportpath' => '@runtime/mail', // path or alias here ], if want still send emails , override recipients can example extend yii\swiftmailer\mailer class.
class mymailer extends \yii\swiftmailer\mailer { public $testmode = false; public $testemail = 'test@test.com'; public function beforesend($message) { if (parent::beforesend($message)) { if ($this->testmode) { $message->setto($this->testemail); } return true; } return false; } } configure it:
'components' => [ // ... 'mailer' => [ 'class' => 'namespace\of\your\class\mymailer', // rest same in normal config ], ], and can use in same way use mailer component time. when it's time switch test mode modify configuration:
'mailer' => [ 'class' => 'namespace\of\your\class\mymailer', 'testmode' => true, 'testemail' => 'test222@test.com', // optional if want send address different default test@test.com // rest same in normal config ], with this, every email overridden recipient address.
Comments
Post a Comment