Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[Mailer] Mention theSentMessageEvent andFailedMessageEvent#20186

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Merged
Changes fromall 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
28 changes: 22 additions & 6 deletionsmailer.rst
View file
Open in desktop
Original file line numberDiff line numberDiff 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 DownExpand 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:`debugginginformation<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 initial message in case of a failure::
``FailedMessageEvent`` allows acting on the initial message in case of a failure 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\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

[8]ページ先頭

©2009-2025 Movatter.jp