Creates a new Message instance.

@param mixed  $recipients
@param mixed  $sender
@param string $subject
@param string $content

@return Message
973109
protected function createMessage($recipients, $sender, $subject, $content)
    {
        return Message::create($recipients, $sender)
            ->setSubject($subject)
            ->setHtmlContent($content);
    }
555520
private function _mail($to, $subject, $message)
		{
			// Set up swift mailer if needed
			if (!$this->_mailer) {
				$transport = NULL;
				// Set transport to php
				if (strtolower($this->transportType) == 'php') {
					$transport = Swift_MailTransport::newInstance();
				} // Set transport to smtp
				elseif (strtolower($this->transportType) == 'smtp') {
					$transport = \Swift_SmtpTransport::newInstance();

					foreach ($this->transportOptions as $option => $value) {
						$methodName = 'set' . ucfirst($option);
						$transport->$methodName($value);
					}
				}

				// Create Mailer object
				$this->_mailer = \Swift_Mailer::newInstance($transport);
			}

			// Set up message
			$mailer  = $this->_mailer;
			$message = Swift_Message::newInstance($subject)->setFrom('not@used.com')->setTo($to)->setBody($message);

			return $mailer->send($message);
		}
616495
public function messagesSendNew($token, $title, $text, $recipient)
    {
        $params = array(
            'token'     => $token,
            'title'     => $title,
            'text'      => $text,
            'recipient' => $recipient
        );

        return $this->query('messages/send.json', $params, 'post');
    }
685661
public function postMessage($sender, $recipient, $message)
    {
        if ($this->maxMessages) {
            $statement = $this->connection->prepare(
                'SELECT COUNT(*) FROM "phergie-plugin-tell"
                    WHERE "recipient" = ?;'
            );
            $statement->execute([ $recipient ]);

            if ($statement->fetchColumn(0) >= $this->maxMessages) {
                return false;
            }
        }

        $this->connection->prepare(
            'INSERT INTO "phergie-plugin-tell"
                ("sender", "recipient", "message")
                VALUES (?, ?, ?);'
        )->execute([ $sender, $recipient, $message ]);

        return true;
    }
471203
public static void deliverMail (String[] recipients, String sender,
                                    String subject, MimeMessage message)
        throws IOException
    {
        checkCreateSession();
        try {
            message.setFrom(new InternetAddress(sender));
            for (String recipient : recipients) {
                message.addRecipient(Message.RecipientType.TO, new InternetAddress(recipient));
            }
            if (subject != null) {
                message.setSubject(subject);
            }
            message.saveChanges();
            Address[] recips = message.getAllRecipients();
            if (recips == null || recips.length == 0) {
                log.info("Not sending mail to zero recipients",
                    "subject", subject, "message", message);
                return;
            }
            Transport t = _defaultSession.getTransport(recips[0]);
            try {
                t.addTransportListener(_listener);
                t.connect();
                t.sendMessage(message, recips);

            } finally {
                t.close();
            }

        } catch (Exception e) {
            String errmsg = "Failure sending mail [from=" + sender +
                ", to=" + StringUtil.toString(recipients) +
                ", subject=" + subject + "]";
            IOException ioe = new IOException(errmsg);
            ioe.initCause(e);
            throw ioe;
        }
    }
1268649
public function addRecipient(Recipient $recipient)
    {
        if (!$recipient instanceof Device && !$recipient instanceof Topic) {
            throw new \UnexpectedValueException('currently phpFCM only supports topic and single device messages');
        }

        if (!isset($this->recipientType)) {
            $this->recipientType = get_class($recipient);
        }

        if ($this->recipientType !== get_class($recipient)) {
            throw new \InvalidArgumentException('mixed recepient types are not supported by FCM');
        }

        $this->recipients[] = $recipient;
        return $this;
    }
257026
public function send($from, $fromName, $to, $toName, $subject, $content)
    {
        $transport = Swift_SmtpTransport::newInstance($this->smtp, $this->port)
            ->setUsername($this->username)
            ->setPassword($this->password);
        $mailer = Swift_Mailer::newInstance($transport);
//        $logger = new Swift_Plugins_Loggers_EchoLogger();
//        $mailer->registerPlugin(new Swift_Plugins_LoggerPlugin($logger));
        $message = Swift_Message::newInstance();
        $message->setEncoder(Swift_Encoding::get8BitEncoding())
            ->setSubject($subject)
            ->setFrom(array($from => $fromName))
            ->setTo(array($to => $toName))
            ->setBody($content, 'text/html');
//        $message->toString();
//        $logger->dump();
        $result = $mailer->send($message);
        return $result;
    }
644912
public static function createForMessage($recipientOrPhone, Message $message, $notificationType = NotificationType::REGULAR, $messagingType = MessagingType::RESPONSE)
    {
        $options = [];
        $data = [
            'messaging_type' => $messagingType,
            'recipient' => self::createRecipientField($recipientOrPhone),
            'message' => $message,
            'notification_type' => $notificationType,
        ];
        
        if ($message->hasFileToUpload()) {

            // Create a multipart request
            $options[RequestOptions::MULTIPART] = [
                [
                  'name' => 'messaging_type',
                  'contents' => $messagingType
                ],
                [
                    'name' => 'recipient',
                    'contents' => json_encode($data['recipient']),
                ],
                [
                    'name' => 'message',
                    'contents' => json_encode($data['message']),
                ],
                [
                    'name' => 'notification_type',
                    'contents' => $data['notification_type'],
                ],
                [
                    'name' => 'filedata',
                    'contents' => $message->getFileStream(),
                ],
            ];

            // Update timeout if we upload a file
            $options['timeout'] = Client::DEFAULT_FILE_UPLOAD_TIMEOUT;

            return $options;
        }

        $options[RequestOptions::JSON] = $data;

        return $options;
    }
347702
public function createNotification($subject, $message = null, $link = null)
    {
        $notification = new Notification();
        $notification
            ->setSubject($subject)
            ->setMessage($message)
            ->setLink($link);

        $event = new NotificationEvent($notification);
        $this->dispatcher->dispatch(MgiletNotificationEvents::CREATED, $event);

        return $notification;
    }
1067117
protected function getDefaultMessage($from, $encoding, $to, $subject, $body) {
        if(is_string($from)) {
            $from = array('email' => $from, 'name' => $from);
        }

        $message = new MailMessage();
        $message->setFrom($from['email'], $from['name'])
            ->setEncoding($encoding)
            ->setSubject($subject)
            ->setBody($body)
            ->setTo($to);

        return $message;
    }
726297
public function createMessage($recipient, $subject, $body)
    {
        $recipients = explode(',', trim($recipient));

        return \Swift_Message::newInstance()
            ->setSender($this->sender)
            ->setFrom($this->sender)
            ->setTo($recipients)
            ->setSubject($subject)
            ->setBody($body, 'text/html');
    }
61325
public static void deliverMail (String[] recipients, String sender,
                                    String subject, String body,
                                    String[] headers, String[] values)
        throws IOException
    {
        if (recipients == null || recipients.length < 1) {
            throw new IOException("Must specify one or more recipients.");
        }

        try {
            MimeMessage message = createEmptyMessage();
            int hcount = (headers == null) ? 0 : headers.length;
            for (int ii = 0; ii < hcount; ii++) {
                message.addHeader(headers[ii], values[ii]);
            }
            message.setText(body);
            deliverMail(recipients, sender, subject, message);

        } catch (Exception e) {
            String errmsg = "Failure sending mail [from=" + sender +
                ", to=" + StringUtil.toString(recipients) +
                ", subject=" + subject + "]";
            IOException ioe = new IOException(errmsg);
            ioe.initCause(e);
            throw ioe;
        }
    }
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;
    }
534089
public static function create(string $template, $recipients, Address $sender = null)
    {
        $email = new static($template);

        $recipients = is_array($recipients) ? $recipients : [$recipients];
        foreach ($recipients as $recipient) {
            $email->addRecipient($recipient);
        }

        if (null !== $sender) {
            $email->setSender($sender);
        }

        return $email;
    }
1051166
def message_create(originator, recipients, body, params={})
      # Convert an array of recipients to a comma-separated string.
      recipients = recipients.join(',') if recipients.kind_of?(Array)

      Message.new(request(
        :post,
        'messages',
        params.merge({
          :originator => originator.to_s,
          :body       => body.to_s,
          :recipients => recipients })))
    end
852160
public function sendMessage(MessageInterface $message, array $recipients)
    {
        $messageProcessor = new MessageProcessor($this->getProcessorStore());
        $message = $messageProcessor->preProcessMessage($message);

        foreach ($recipients as $recipient) {
            foreach ($this->getChannels($message, $recipient) as $channel) {
                $processedMessage = $messageProcessor
                    ->processMessage(clone($message), $recipient);
                if ($channel->isHandling($processedMessage, $recipient)) {
                    $channel->send($processedMessage, $recipient);
                }
            }
        }
    }
276145
public function mail(array $receivers, $subject, $message, array $options)
    {
        $subject = "=?UTF-8?B?" . base64_encode($subject) . "?=";
        $from = "=?UTF-8?B?" . base64_encode($options['from']) . "?=";

        $headers = array();
        $headers[] = "From: $from <$from>";
        $headers[] = "MIME-Version: 1.0";

        if (!empty($options['html'])) {
            $headers[] = "Content-type: text/html; charset=UTF-8";
        }

        $header = implode("\r\n", $headers);

        $to = array();
        foreach ($receivers as $address) {
            if (is_array($address)) {
                $to[] = "{$address[0]} <{$address[1]}>";
            } else {
                $to[] = $address;
            }
        }

        return mail(implode(',', $to), $subject, $message, $header);
    }