TODO

@param $to
@param $subject
@param $message
@return \Swift_Message
345175
public function build($to, $subject, $message)
    {
        $mail = new \Swift_Message($subject, $message, 'text/html', 'UTF-8');
        $mail->setFrom($this->from, $this->fromName);
        $mail->setTo($to);
        return $mail;
    }
809217
private function getMessage($subject)
    {
        if (method_exists($subject, 'getMessage')) {
            $message = $subject->getMessage();
        } else {
            $message = $this->useReflectionToGetMessage($subject);
        }

        return $message;
    }
433587
protected function sendMessage($to, $message)
    {
        if ($message instanceof HipChatMessage) {
            return $this->hipChat->sendMessage($to, $message->toArray());
        }

        if ($message instanceof HipChatFile) {
            return $this->hipChat->shareFile($to, $message->toArray());
        }
    }
1147405
public function notify($to, $message)
    {
        $params = [
            'id'             => $to,
            'from'           => $this->config['from'],
            'message'        => $message,
            'notify'         => Arr::get($this->config, 'notify', false),
            'message_format' => Arr::get($this->config, 'format', 'text'),
        ];

        $color = Arr::get($this->config, 'color', 'yellow');

        if (!in_array($color, $this->colours)) {
            $color = 'yellow';
        }

        $params['color'] = $color;

        $type = Arr::get($this->config, 'type', 'message');

        return $this->send($this->buildUrlFromString("room/{$to}/{$type}"), $params);
    }
519083
public function createMessage($subject = null, $body = null, $contentType = null, $charset = null)
    {
        $message = Swift_Message::newInstance($subject, $body, $contentType, $charset);

        if(null !== $this->fromEmail) {
            
            if(null === $this->fromName) {
                $message->setFrom($this->fromEmail);
            } else {
                $message->setFrom($this->fromEmail, $this->fromName);
            }
            
        }

        return $message;
    }
1181746
public function notify($to, $message)
    {
        $params = ['text' => $message];

        return $this->send($this->buildUrlFromString("rooms/{$to}/chatMessages"), $params);
    }
1299835
public function message($to, $message, $mediaUrls = null, array $params = [])
    {
        $params['body'] = $message;

        if (!isset($params['from'])) {
            $params['from'] = $this->from;
        }

        if (!empty($mediaUrls)) {
            $params['mediaUrl'] = $mediaUrls;
        }

        return $this->getTwilio()->messages->create($to, $params);
    }
341784
public function signMessage(Swift_Message $message)
    {
        if (null === $this->signCertificate && null === $this->encryptCert) {
            return $this;
        }

        if ($this->signThenEncrypt) {
            $this->smimeSignMessage($message);
            $this->smimeEncryptMessage($message);
        } else {
            $this->smimeEncryptMessage($message);
            $this->smimeSignMessage($message);
        }
    }
149763
protected function sendMail($to, $subject, $body, $headers)
    {
        return mail(
            $to,
            $subject,
            $body,
            $headers
        );
    }
818879
public function send($to, $subject, $message, $from = 'default', $headerExtra = [], $html = true) {
        if (!is_null($this->method)) { // if a method is set then use that one
            if (is_string($this->method) && ('swift' == $this->method)) {
                return $this->_swiftMail($to, is_string($from) ? $this->from[$from] : $from, $subject, $message, [], $html);
            } else {
                return call_user_func($this->method, $to, is_string($from) ? $this->from[$from] : $from, $subject, $message, [], $headerExtra, $html);
            }
        } // if not use default
        return $this->_mail($to, is_string($from) ? $this->from[$from] : $from, $subject, $message, [], $headerExtra, $html);
    }
742896
protected function makeCall(TwilioCallMessage $message, $to)
    {
        $params = [
            'url' => trim($message->content),
        ];

        $this->fillOptionalParams($params, $message, [
            'statusCallback',
            'statusCallbackMethod',
            'method',
            'status',
            'fallbackUrl',
            'fallbackMethod',
        ]);

        if (! $from = $this->getFrom($message)) {
            throw CouldNotSendNotification::missingFrom();
        }

        return $this->twilioService->calls->create(
            $to,
            $from,
            $params
        );
    }
1067652
protected function buildMessage($content, array $records)
    {
        $message = null;
        if ($this->messageTemplate instanceof \Swift_Message) {
            $message = clone $this->messageTemplate;
            $message->generateId();
        } elseif (is_callable($this->messageTemplate)) {
            $message = call_user_func($this->messageTemplate, $content, $records);
        }

        if (!$message instanceof \Swift_Message) {
            throw new \InvalidArgumentException('Could not resolve message as instance of Swift_Message or a callable returning it');
        }

        if ($records) {
            $subjectFormatter = new LineFormatter($message->getSubject());
            $message->setSubject($subjectFormatter->format($this->getHighestRecord($records)));
        }

        $message->setBody($content);
        $message->setDate(time());

        return $message;
    }
674960
private function useReflectionToGetMessage($subject)
    {
        $reflection = new \ReflectionClass($subject);
        $property   = $reflection->getProperty('_message');
        $property->setAccessible(true);
        $message = $property->getValue($subject);

        return $message;
    }
225219
public function createMessageAction(Subject $subject)
    {
        $form = $this->container->get('form.factory')->create(new MessageType, new Message());
        $form->handleRequest($this->get('request'));


        if ($form->isValid()) {
            $message = $form->getData();
            $this->manager->createMessage($message, $subject);
        }

        return new RedirectResponse(
            $this->generateUrl('claro_forum_messages', array('subject' => $subject->getId()))
        );
    }
514839
protected function getTo(Swift_Mime_SimpleMessage $message)
    {
        $to = [];

        if ($message->getTo()) {
            $to = array_merge($to, array_keys($message->getTo()));
        }

        if ($message->getCc()) {
            $to = array_merge($to, array_keys($message->getCc()));
        }

        if ($message->getBcc()) {
            $to = array_merge($to, array_keys($message->getBcc()));
        }

        return $to;
    }
789445
public static function mail($text, $subject = null, $to = null)
    {
        if (!self::isDebug()) {
            return false;
        }

        $_this = self::i();

        if (empty($subject)) {
            $subject = self::$_config['mail']['subject'];
        }

        if (empty($to)) {
            $to = isset(self::$_config['mail']['to'])
                ? self::$_config['mail']['to']
                : 'jbdump@' . $_SERVER['HTTP_HOST'];
        }

        if (is_array($to)) {
            $to = implode(', ', $to);
        }

        // message
        $message   = array();
        $message[] = '<html><body>';
        $message[] = '<p><b>JBDump mail from '
            . '<a href="http://' . $_SERVER['HTTP_HOST'] . '">' . $_SERVER['HTTP_HOST'] . '</a>'
            . '</b></p>';

        $message[] = '<p><b>Date</b>: ' . date(DATE_RFC822, time()) . '</p>';
        $message[] = '<p><b>IP</b>: ' . self::getClientIP() . '</p>';
        $message[] = '<b>Debug message</b>: <pre>' . print_r($text, true) . '</pre>';
        $message[] = '</body></html>';
        $message   = wordwrap(implode(PHP_EOL, $message), 70);

        // To send HTML mail, the Content-type header must be set
        $headers   = array();
        $headers[] = 'MIME-Version: 1.0';
        $headers[] = 'Content-type: text/html; charset=utf-8';
        $headers[] = 'To: ' . $to;
        $headers[] = 'From: JBDump debug <jbdump@' . $_SERVER['HTTP_HOST'] . '>';
        $headers[] = 'X-Mailer: JBDump v' . self::VERSION;
        $headers   = implode("\r\n", $headers);

        $result = mail($to, $subject, $message, $headers);
        if (self::$_config['mail']['log']) {
            $_this->log(
                array(
                    'email'   => $to,
                    'subject' => $subject,
                    'message' => $message,
                    'headers' => $headers,
                    'result'  => $result
                ),
                'JBDump::mail'
            );
        }

        return $result;
    }
243424
private function getReplyTo(Swift_Mime_SimpleMessage $message)
    {
        if ($message->getReplyTo()) {
            foreach ($message->getReplyTo() as $email => $name) {
                return ['email' => $email, 'name' => $name];
            }
        }
        return null;
    }