0

In my app i have many sender and the smtp server require authentication for every sender before sending message.

Note: my senders are stored in database with their password

How i can implement this in symfony mailer to retrieve password and authenticate before send message ?

Thank you

Is this feature is implemented in symfony mailer?

Jozeph B.
  • 26
  • 4

1 Answers1

0

It is possible to achieve that. You will need to create a service where you get the password of the user, you will have to use depency injectio (Entity manager) and call for this password.

Then, you need to configure the mailer properly to set your user infos, it is located in config/packages/mailer.yaml.

framework:
    mailer:
        dsn: 'smtp://localhost'
        # Default options for all senders are here

        # User specific options
        senders:
            # User 1
            user1:
                transport: 'smtp'
                host: 'your-smtp-server'
                username: 'user1@example.com'
                password: '%env(USER1_PASSWORD)%'
                # Other options you might need

finally, you need what is called a 'Factory' (here the doc about using a factory to create services : https://symfony.com/doc/current/service_container/factories.html).

It will be a function where you use the MailerInterface to get the password of your user and set it in the transport option.

Don't forget to register your mailer factory service in your config/service.yaml file.

Lou
  • 26
  • 2
  • 5