asEmailMessage example

$this->transport = $transport;
        $this->bus = $bus;
        $this->from = $from ?: $envelope?->getSender();
        $this->envelope = $envelope;
    }

    public function notify(Notification $notification, RecipientInterface $recipient, string $transportName = null): void
    {
        $message = null;
        if ($notification instanceof EmailNotificationInterface) {
            $message = $notification->asEmailMessage($recipient$transportName);
        }

        $message ??= EmailMessage::fromNotification($notification$recipient$transportName);
        $email = $message->getMessage();
        if ($email instanceof Email) {
            if (!$email->getFrom()) {
                if (null === $this->from) {
                    throw new LogicException(sprintf('To send the "%s" notification by email, you should either configure a global "from" header, set a sender in the global "envelope" of the mailer configuration or set a "from" header in the "asEmailMessage()" method.', get_debug_type($notification)));
                }

                $email->from($this->from);
            }
Home | Imprint | This part of the site doesn't use cookies.