Skip to content

[Mailer] add tag and metadata docs #13022

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 5, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions mailer.rst
Original file line number Diff line number Diff line change
Expand Up @@ -730,6 +730,47 @@ adding a text header ``X-Transport`` to an email::
$email->getHeaders()->addTextHeader('X-Transport', 'important');
$mailer->send($email);

Adding Tags and Metadata to Emails
----------------------------------

Certain 3rd party transports support email *tags* and *metadata*. These can be
used by the 3rd party service for grouping, tracking and workflows. The
:class:`Symfony\\Component\\Mailer\\Header\\TagHeader` and
:class:`Symfony\\Component\\Mailer\\Header\\MetadataHeader` headers can be
added to your email. If your transport supports these headers, they will be
applied in the format specific to the transport.

.. versionadded:: 5.1

The :class:`Symfony\\Component\\Mailer\\Header\\TagHeader` and
:class:`Symfony\\Component\\Mailer\\Header\\MetadataHeader` classes were
introduced in Symfony 5.1.

The following 3rd party transports currently support tags and metadata:

* Postmark
* Mailgun
* MailChimp

For example, say you want to tag an email and add some metadata::

use Symfony\Component\Mailer\Header\MetadataHeader;
use Symfony\Component\Mailer\Header\TagHeader;

$email->getHeaders()->add(new TagHeader('password-reset'));
$email->getHeaders()->add(new MetadataHeader('Color', 'blue'));
$email->getHeaders()->add(new MetadataHeader('Client-ID', '12345'));

When sending this email with a transport that supports tags and metadata, the transport
will convert these to their appropriate format. If using a transport that does not
support tags and metadata, they will be added as custom headers:

.. code-block:: text

X-Tag: password-reset
X-Metadata-Color: blue
X-Metadata-Client-ID: 12345

Development & Debugging
-----------------------

Expand Down