Create message callback.

@param  \Orchestra\Contracts\Notification\Recipient  $user
@param  string|null  $subject
@param  callable|null  $callback

@return \Closure
343739
protected function createMessageCallback(Recipient $user, $subject = null, $callback = null)
    {
        return function (Message $message) use ($user, $subject, $callback) {
            // Set the recipient detail.
            $message->to($user->getRecipientEmail(), $user->getRecipientName());

            // Only append the subject if it was provided.
            ! empty($subject) && $message->subject($subject);

            // Run any callback if provided.
            \is_callable($callback) && $callback(...func_get_args());
        };
    }
1230835
public function aroundSendMessage(
        TransportInterface $subject,
        \Closure $proceed
    ) {
        $storeId = $this->registry->registry('transportBuilderPluginStoreId');
        if ($this->helper->isEnabled($storeId)) {
            try {
                $this->smtpTransportAdapter->send($subject, $storeId);

            } catch (\Exception $e) {
                $this->dataHelper->log("TransportPlugin send exception: " . $e->getMessage());
                return $proceed();
            }
        } else {
            return $proceed();
        }
    }
1090703
public function executeSending( $subject, $body, $subscriber )
    {
        $email = $subscriber->attribute( 'email' );
        $parameters = array();
        $parameters['content_type'] = $this->emailContentType;
        $parameters['from'] = $this->emailFrom;
        $transport = eZNotificationTransport::instance( 'ezmail' );
        $result = $transport->send( array( $email ), $subject, $body, null, $parameters );
        if ( $result === false )
        {
            throw new Exception( 'Send email error! Subscriber id:' .$subscriber->attribute( 'id' ) );
        }
        eZDebugSetting::writeNotice( 'extension-ezcomments', "An email has been sent to '$email' (subject: $subject)", __METHOD__ );
    }
59777
public function initialize($subject, $callback=null)
    {
        $class = is_string($subject) ? ltrim($subject,'\\') : $subject::className();

        // initialize the object if needed
        if (!isset($this->_schema[$class])) {
            $builder = new \Pheasant\SchemaBuilder($this);
            $initializer = $callback ? $callback : $class.'::initialize';

            $this->events()->trigger('beforeInitialize', $builder);
            call_user_func($initializer, $builder, $this);
            $schema = $builder->build($class);

            $this->_schema[$class] = $schema;
            $this->events()->trigger('afterInitialize', $schema);
        }

        return $class;
    }
680990
protected function sendNewEmailSimple($body, $subject, $emailTo = '', 
        $emailID = -3, $treeID = -3, $coreID = -3, $userTo = -3)
    {
        $emaTo = [];
        if (is_array($emailTo)) {
            $emaTo = $emailTo;
            $emailTo = $emailTo[1] . ' <' . $emailTo[0] . '>';
        } elseif (trim($emailTo) != '') {
            $emaUsr = User::where('email', $emailTo)->first();
            if ($emaUsr && isset($emaUsr->name)) {
                $emaTo[] = [$emailTo, $emaUsr->name];
            }
        }
        if ($GLOBALS["SL"]->isHomestead()) {
            echo '<div class="container"><h2>' . $subject . '</h2>' . $body . '<hr><hr></div>';
        } else {
            $this->sendEmail($body, $subject, $emaTo);
        }
        return $this->logEmailSent($body, $subject, $emailTo, $emailID, $treeID, $coreID, $userTo);
    }
609671
public function sendCustomerConfirmation(
        $recipient,
        ApiOrderInterface $apiOrder,
        ContactInterface $customerContact = null
    ) {
        if (!$this->sendEmailConfirmationToCustomer) {
            return false;
        }

        return $this->sendConfirmationEmail(
            $recipient,
            $apiOrder,
            $this->templateCustomerConfirmationPath,
            $customerContact
        );
    }
162683
public function sendActivationMail($user)
    {
        if ($user->activated || !$this->shouldSend($user)) {
            return;
        }
        $userToken = $this->createActivation($user);
        //$userToken = User::find($user->id);
        $user->notify(new ConfirmEmailNotification($userToken));
    }
794087
public function sendMessage($recipient, $message, $notificationType = NotificationType::REGULAR, $messagingType = MessagingType::RESPONSE)
    {
        $message = $this->createMessage($message);
        $options = RequestOptionsFactory::createForMessage($recipient, $message, $notificationType, $messagingType);
        $response = $this->client->send('POST', '/me/messages', null, [], [], $options);
        $responseData = $this->decodeResponse($response);

        return new MessageResponse($responseData['recipient_id'], $responseData['message_id']);
    }
596651
public function messagePage(ServerRequestInterface $request, UserInterface $user): ResponseInterface
    {
        $referer = $request->getHeaderLine('referer');

        $body    = $request->get('body', '');
        $subject = $request->get('subject', '');
        $to      = $request->get('to', '');
        $url     = $request->get('url', $referer);

        $to_user = $this->user_service->findByUserName($to);

        if ($to_user === null || $to_user->getPreference('contactmethod') === 'none') {
            throw new AccessDeniedHttpException('Invalid contact user id');
        }

        $title = I18N::translate('Send a message');

        return $this->viewResponse('message-page', [
            'body'    => $body,
            'from'    => $user,
            'subject' => $subject,
            'title'   => $title,
            'to'      => $to_user,
            'url'     => $url,
        ]);
    }
1202569
public function waitForEmailWithSubject($subject, $timeout = 5)
    {
        $condition = function () use ($subject) {
            $emails = $this->fetchMessages();
            foreach ($emails as $email) {
                $constraint = Assert::equalTo($subject);
                if ($constraint->evaluate($email->subject, '', true)) {
                    return true;
                }
            }

            return false;
        };

        $message = sprintf('Waited for %d secs but no email with the subject of %s has arrived', $timeout, $subject);

        $this->wait($timeout)->until($condition, $message);
    }
1140110
private function getMessage(string $subject, string $message): \Swift_Message
    {
        $messageObject = new \Swift_Message($subject, $message);
        $messageObject
            ->setFrom([$this->config('mailer.sender_email') => $this->config('mailer.sender_name')])
            ->setTo($this->config('mailer.recipients'))
        ;

        return $messageObject;
    }
791639
protected function createBuilder(array $recipients, $data, $callback)
    {
        $messageBuilder = new MessageBuilder($recipients, $data, $callback);

        if ($developerTo = $this->config->get('mail.overwrite_to')) {
            $messageBuilder->setOverwriteTo($developerTo);
        }

        return $messageBuilder;
    }
549427
protected function call($eventName, $subject = null, $message = null)
    {
        if (!isset($this->events[$eventName])) {
            return $subject;
        }

        foreach ($this->events[$eventName] as $listener) {
            if ($this->stop) {
                break;
            }

            $subject = $listener($this->container, $subject, $message, $eventName);
        }

        return $subject;
    }
1275085
public function receiveAnEmailWithSubject($subject)
    {
        $message = $this->fetchLastMessage();
        $this->assertEquals($subject, $message->subject);
    }
259644
public function sendWelcomeMessage(User $user, Token $token = null, $showPassword = false)
    {
        return $this->sendMessage(
            $user->email,
            $this->getWelcomeSubject(),
            'welcome',
            ['user' => $user, 'token' => $token, 'module' => $this->module, 'showPassword' => $showPassword]
        );
    }
1137014
protected function isCreator($subject, UserInterface $user)
    {
        return $subject instanceof BlameableInterface &&
               $subject->getCreatedBy() === $user->getUsername();
    }
24417
public function sendReminder(RemindableInterface $user, $token, Closure $callback = null)
	{
		// We will use the reminder view that was given to the broker to display the
		// password reminder e-mail. We'll pass a "token" variable into the views
		// so that it may be displayed for an user to click for password reset.
		$view = $this->reminderView;

		return $this->mailer->send($view, compact('token', 'user'), function($m) use ($user, $token, $callback)
		{
			$m->to($user->getReminderEmail());

			if ( ! is_null($callback)) call_user_func($callback, $m, $user, $token);
		});
	}