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:[email protected]: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('[email protected]', 'Example'))
->to('[email protected]')
->subject('Subject')
->htmlTemplate('emails/my-template.html.twig')
->context([]);
$customMailer->send($email);