How to Work with Services Provided by Third-Party Bundles

Since Symfony and all third-party bundles configure and retrieve their services
via the container, you can easily access them or even use them in your own
services. To keep things simple, Symfony by default does not require that
controllers must be defined as services. Furthermore, Symfony injects the entire
service container into your controller. For example, to handle the storage of
information on a user's session, Symfony provides a session service,
which you can access inside a standard controller as follows:

In Symfony, you'll constantly use services provided by the Symfony core or
other third-party bundles to perform tasks such as rendering templates (templating),
sending emails (mailer), or accessing information on the request through the request stack (request_stack).

You can take this a step further by using these services inside services that
you've created for your application. Beginning by modifying the NewsletterManager
to use the real Symfony mailer service (instead of the pretend app.mailer).
Also pass the templating engine service to the NewsletterManager
so that it can generate the email content via a template:

The app.newsletter_manager service now has access to the core mailer
and templating services. This is a common way to create services specific
to your application that leverage the power of different services within
the framework.

Tip

Be sure that the swiftmailer entry appears in your application
configuration. As was mentioned in Importing Configuration via Container Extensions,
the swiftmailer key invokes the service extension from the
SwiftmailerBundle, which registers the mailer service.