I'm trying to send an email with dynamic SMTP connection parameters. These parameters will be retrieved from a DB. So specifying the parameters in .env
file (e.g.: MAILER_DSN=smtp://user:pass@smtp.example.com:port
) as explained in official docs or defining multiples transports in .yaml
files don't fit my requirements.
How could I send an email defining the mailer transport programmatically? For example, I'd like to make:
// I'd like to define $customMailer with some data retrieved from DB
$email = (new TemplatedEmail())
->from(new Address('example-from@example.com', 'Example'))
->to('example-to@example.com')
->subject('Subject')
->htmlTemplate('emails/my-template.html.twig')
->context([]);
$customMailer->send($email);