boonkerz
boonkerz

Reputation: 47

Symfony Mailer Dynamic Transport from Database

I would like to specify the SMTP server settings (host, port, password, etc.) through an interface and stored them in a database table so that the user can change this without developer intervention.

How can I accomplish this with the mailer component?

Upvotes: 3

Views: 1350

Answers (1)

Alessandro Chitolina
Alessandro Chitolina

Reputation: 906

Two scenarios:

First: You have multiple configurations on database and you want to choose how to send email from a list of providers

You can implement a transport (Symfony\Component\Mailer\Transport\TransportInterface) which retrieves the correct SMTP settings from db, passing the provider name or id in a message header (remember to delete the header before sending).

Or you can use Mailer as a standalone component, instead of relaying on the one integrated (autoconfigurated and autowired) in the framework. In this case you have to instantiate a new Symfony\Component\Mailer\Mailer class with the appropriate transport when you want to send the mail.

Second: You have only one provider on database and you just want to be able to change SMTP settings at runtime

You can relay on framework integration, implementing your own transport which retrieves the settings from db and create a delegated transport to effectively send the messages.

Upvotes: 2

Related Questions