Symfony

Mailer Component

Email service, transports, Twig email templates, attachments, inline images, Mailer events

16 interview questionsยท
Mid-Level
1

Which interface should be used to inject the email sending service in Symfony?

Answer

MailerInterface is the main interface for sending emails in Symfony. It exposes a send() method that accepts a RawMessage or Email object. Injecting this interface enables autowiring and facilitates mocking in unit tests.

2

How to configure the mailer DSN in Symfony?

Answer

The mailer DSN is configured via the MAILER_DSN environment variable. This approach follows Symfony best practices by separating sensitive configuration from code. The DSN format varies depending on the transport used (smtp, sendmail, or third-party services like mailgun, postmark, sendgrid).

3

Which class should be used to create an email with a Twig template?

Answer

TemplatedEmail is the dedicated class for creating emails using Twig templates. It extends the Email class and adds the htmlTemplate() and textTemplate() methods to specify templates. The context() method allows passing variables to the Twig template.

4

How to add an attachment to a Symfony email?

5

Which method allows embedding an image directly in the HTML body of an email?

+13 interview questions

Master Symfony for your next interview

Access all questions, flashcards, technical tests, code review exercises and interview simulators.

Start for free