Skip to content

Commit

Permalink
[Mailer] Mention the SentMessageEvent and FailedMessageEvent in the d…
Browse files Browse the repository at this point in the history
…ebug section
  • Loading branch information
wkania committed Sep 1, 2024
1 parent 08e3831 commit 69e0ddd
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions mailer.rst
Original file line number Diff line number Diff line change
Expand Up @@ -802,6 +802,8 @@ Catch that exception to recover from the error or to display some message::
// error message or try to resend the message
}

.. _mailer-debugging-emails:

Debugging Emails
----------------

Expand All @@ -810,6 +812,9 @@ The :class:`Symfony\\Component\\Mailer\\SentMessage` object returned by the
provides access to the original message (``getOriginalMessage()``) and to some
debug information (``getDebug()``) such as the HTTP calls done by the HTTP
transports, which is useful to debug errors.
Access to :class:`Symfony\\Component\\Mailer\\SentMessage` can also be obtained by listening
to the :ref:`SentMessageEvent <mailer-sent-message-event>`, and to ``getDebug()`` by listening
to the :ref:`FailedMessageEvent <mailer-failed-message-event>`."

.. note::

Expand Down Expand Up @@ -1712,6 +1717,8 @@ and their priorities:
$ php bin/console debug:event-dispatcher "Symfony\Component\Mailer\Event\MessageEvent"
.. _mailer-sent-message-event:

SentMessageEvent
~~~~~~~~~~~~~~~~

Expand All @@ -1722,16 +1729,17 @@ SentMessageEvent
The ``SentMessageEvent`` event was introduced in Symfony 6.2.

``SentMessageEvent`` allows you to act on the :class:`Symfony\\Component\\\Mailer\\\SentMessage`
class to access the original message (``getOriginalMessage()``) and some debugging
information (``getDebug()``) such as the HTTP calls made by the HTTP transports,
which is useful for debugging errors::
class to access the original message (``getOriginalMessage()``) and some
:ref:`debugging information <mailer-debugging-emails>` (``getDebug()``) such as the HTTP calls
made by the HTTP transports, which is useful for debugging errors::

use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Mailer\Event\SentMessageEvent;

public function onMessage(SentMessageEvent $event): void
{
$message = $event->getMessage();
// e.g you can get mail id
$event->getMessage();

// do something with the message
}
Expand All @@ -1743,6 +1751,8 @@ and their priorities:
$ php bin/console debug:event-dispatcher "Symfony\Component\Mailer\Event\SentMessageEvent"
.. _mailer-failed-message-event:

FailedMessageEvent
~~~~~~~~~~~~~~~~~~

Expand All @@ -1752,15 +1762,21 @@ FailedMessageEvent

The ``FailedMessageEvent`` event was introduced in Symfony 6.2.

``FailedMessageEvent`` allows acting on the the initial message in case of a failure::
``FailedMessageEvent`` allows acting on the the initial message in case of a failure and some

Check failure on line 1765 in mailer.rst

View workflow job for this annotation

GitHub Actions / Lint (DOCtor-RST)

The word "the" is used more times in a row.
:ref:`debugging information <mailer-debugging-emails>` (``getDebug()``) such as the HTTP calls made
by the HTTP transports, which is useful for debugging errors::

use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Mailer\Event\FailedMessageEvent;
use Symfony\Component\Mailer\Exception\TransportExceptionInterface;

public function onMessage(FailedMessageEvent $event): void
{
// e.g you can get more information on this error when sending an email
$event->getError();
$error = $event->getError();
if ($error instanceof TransportExceptionInterface) {
$error->getDebug();
}

// do something with the message
}
Expand Down

0 comments on commit 69e0ddd

Please sign in to comment.