Consuming emails async in Symfony 5

I use Symfony 5 messanger to handle emails sending in async way. I have:

  • email DNS configured in .env

    MAILER_DSN=smtp://localhost

  • messanger transport DNS in .env (I use database to store emails queue)

    MESSENGER_TRANSPORT_DSN=doctrine://default

  • transports and routing in messenger.yaml

      serializer:
          default_serializer: messenger.transport.symfony_serializer
    
      transports:
          # https://symfony.com/doc/current/messenger.html#transport-configuration
          async: '%env(MESSENGER_TRANSPORT_DSN)%'
          failed: 'doctrine://default?queue_name=failed'
    
          # sync: 'sync://'
    
      routing:
          # Route your messages to the transports
          # 'AppMessageYourMessage': async
          'SymfonyComponentMailerMessengerSendEmailMessage':  async
    

Current situation: sending emails to queue works – using mailer results in inserting record in database table messanger_messages.

Problem: If I understood docs correctly, for async emails processing, first emails are queued into DB (for my case) and they are then sent one by one with command php bin/console messenger:consume -vv async. Unfortunatelly executing this command does not result in emails being sent. Records in database remain the same, they do not fall into failed category and no emails are generated.

To be sure that sending configuration is correct I switched to sync method and in this case emails are immediately generated and sent. So my question is wheter there is another step which should be done to make queued emails to be consumed eg. writting custom sending handler (I assumed that messanger:consume command will do this for me) or if there is any other part of this process I missed which causes that queued emails are not consumed.

Source: Symfony Questions

Was this helpful?

0 / 0

Leave a Reply 0

Your email address will not be published. Required fields are marked *