-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
Closed
Description
Is it a good idea to introduce the getTransport method into the Mailer class so that it can be modified?
I did this because it seemed to me the easiest way to solve the problem of sending emails via SMTP, using authentication data stored in the database (in my case in Website entities);
// vendor/symfony/mailer/Mailer.php
...
class Mailer implements MailerInterface
{
...
public function getTransport() : TransportInterface {
return $this->transport;
}
...
}
// and in my service:
public function __construct(
Symfony\Component\Mailer\MailerInterface $mailer
){
$this->mailer = $mailer;
}
public function getMailer(Website $website){
$this->mailer->getTransport()
->setUsername($website->getSmtpUsername())
->setPassword($website->getSmtpPassword());
$transport->getStream()
->setHost($website->getSmtpHost())
->setPort($website->getSmtpPort());
return $this->mailer;
}