Nada_Surf Nada_Surf - 4 months ago 31
PHP Question

Symfony 2.3: How do you configure SwiftMailer to automatically use a custom plugin?

I have created a custom SwiftMailer plugin which I would like to have SwiftMailer use by default in my Symfony 2.3 application. The only documentation I can find in this regard is here: http://symfony.com/doc/current/reference/dic_tags.html#swiftmailer-plugin

I have set up the service as follows:

acme_test_bundle.swiftmailer.embed_images:
class: Acme\TestBundle\SwiftMailer\Plugins\ImageEmbedPlugin
tags:
- { name: swiftmailer.plugin }


SwiftMailer is not using the plugin even though this service has been created. Have I done something wrong and is there anything else I should be doing?

Answer

I managed to figure this out myself.

Contrary to what the Symfony 2.3 documentation says, you need to tag the service with which mailer you will be using (usually the 'default' one).

Therefore, I needed to change swiftmailer.plugin to swiftmailer.default.plugin

So, the service definition is now:

acme_test_bundle.swiftmailer.embed_images:
    class: Acme\TestBundle\SwiftMailer\Plugins\ImageEmbedPlugin
    tags:
        - { name: swiftmailer.default.plugin }