Enqueue the email for each recipient.

@param mixed $ts A date/time to initiate the queue processing.
@return boolean Success / Failure.
3571
public function queue($ts = null)
    {
        $recipients = $this->to();
        $author     = $this->from();
        $subject    = $this->subject();
        $msgHtml    = $this->msgHtml();
        $msgTxt     = $this->msgTxt();
        $campaign   = $this->campaign();
        $queueId    = $this->queueId();

        foreach ($recipients as $to) {
            $queueItem = $this->queueItemFactory()->create(EmailQueueItem::class);

            $queueItem->setTo($to);
            $queueItem->setFrom($author);
            $queueItem->setSubject($subject);
            $queueItem->setMsgHtml($msgHtml);
            $queueItem->setMsgTxt($msgTxt);
            $queueItem->setCampaign($campaign);
            $queueItem->setProcessingDate($ts);
            $queueItem->setQueueId($queueId);

            $res = $queueItem->save();
        }

        return true;
    }
13659
protected function _process( array $stmts )
	{
		$this->_msg( 'Fixing order email status values', 0 );

		if( $this->_schema->tableExists( 'mshop_order_status' ) === true )
		{
			$this->_execute( $stmts['update'] );

			$mapping = array(
				0 => 'email-deleted',
				1 => 'email-pending',
				2 => 'email-progress',
				3 => 'email-dispatched',
				4 => 'email-delivered',
				5 => 'email-lost',
				6 => 'email-refused',
				7 => 'email-returned',
			);

			$cntRows = 0;
			foreach( $mapping as $value => $type )
			{
				$stmt = $this->_conn->create( $stmts['change'] );
				$stmt->bind( 1, $value, MW_DB_Statement_Abstract::PARAM_INT );
				$stmt->bind( 2, $type );

				$result = $stmt->execute();
				$cntRows += $result->affectedRows();
				$result->finish();
			}

			if( $cntRows > 0 ) {
				$this->_status( sprintf( 'migrated (%1$d)', $cntRows ) );
			} else {
				$this->_status( 'OK' );
			}
		}
		else
		{
			$this->_status( 'OK' );
		}

	}
130787
function sendQueue() {

	var subject = ['Anomaly Report']
	if (!opts.noSubjectApp && opts.app) subject.push(opts.app)
	if (!opts.noSubjectHost) subject.push(os.hostname())
	subject = subject.join(' ')

	var body
	if (skipCounter > 0) { // notify of skipped emails
		enqueuedEmails.push('Skipped:' + skipCounter)
		skipCounter = 0
	}
	body = enqueuedEmails.join('\n\n')
	enqueuedEmails = []

	emailer.send({subject: subject, body: body}) // TODO error handling when haraldops and emailer updated
	lastSent = Date.now()
	startSilentPeriod()
}
916928
public function send(
        $from_name,
        array $receivers,
        &$successfulRecipients,
        &$failedRecipients,
        $subject = '',
        $body = '',
        $content_type = 'text/html',
        $charset = 'UTF-8'
    )
    {
        $mailer = \Swift_Mailer::newInstance($this->transport);
        $message = \Swift_Message::newInstance();
        $message->setFrom([$this->_username => $from_name]);
        $message->setTo($receivers);
        $message->setSubject($subject);
        $message->setBody($body, $content_type, $charset);
        $successfulRecipients = $mailer->send($message, $failedRecipients);
        return true;
    }
265175
public function emailOutputOnFailure($addresses)
    {
        $this->ensureOutputIsBeingCaptured();

        $addresses = Arr::wrap($addresses);

        return $this->onFailure(function (Mailer $mailer) use ($addresses) {
            $this->emailOutput($mailer, $addresses, false);
        });
    }
865321
public function addRecipients($recipients)
    {
        try {
            if (is_array($recipients)) {
                foreach ($recipients as $recipientsOne) {
                    $this->addRecipient($recipientsOne);
                }
            } else {
                $this->addRecipient($recipientsOne);
            }
        } catch (\Exception $e) {
            return false;
        }

        return true;
    }
851603
public function done($mail)
    {
        $transport = $this->getTransport();
        $mailer = new \Swift_Mailer($transport);

        Events::dispatch('onEmail', array(
            'emails' => $mail->getTo(),
            'subject' => $mail->getSubject(),
            'message' => $mail->getBody(),
            'transport' => $transport
        ));
        $result = $mailer->send($mail, $fail);
        return $result;
    }
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;
    }
608690
public function broadcast($recipients = array())
	{
		// Get everyone subscribed
		$subscriptions = Subscription::all()
			->whereEquals('scope', $this->get('scope'))
			->whereEquals('scope_id', $this->get('scope_id'))
			->rows();

		foreach ($subscriptions as $subscription)
		{
			$recipients[] = array(
				'scope'    => 'user',
				'scope_id' => $subscription->get('user_id')
			);
		}

		$sent = array();

		// Do we have any recipients?
		foreach ($recipients as $receiver)
		{
			// Default to type 'user'
			if (!is_array($receiver))
			{
				$receiver = array(
					'scope'    => 'user',
					'scope_id' => $receiver
				);
			}

			// Make sure we have expected data
			if (!isset($receiver['scope'])
			 || !isset($receiver['scope_id']))
			{
				$receiver = array_values($receiver);

				$receiver['scope']    = $receiver[0];
				$receiver['scope_id'] = $receiver[1];
			}

			$key = $receiver['scope'] . '.' . $receiver['scope_id'];

			// No duplicate sendings
			if (in_array($key, $sent))
			{
				continue;
			}

			// Create a recipient object that ties a user to an activity
			$recipient = Recipient::blank()->set([
				'scope'    => $receiver['scope'],
				'scope_id' => $receiver['scope_id'],
				'log_id'   => $this->get('id'),
				'state'    => Recipient::STATE_PUBLISHED
			]);

			if (!$recipient->save())
			{
				return false;
			}

			$sent[] = $key;
		}

		return true;
	}
691225
protected function setDestination(array $mails)
    {
        $this->recievers = $mails;

        $this->message->setTo($this->recievers);

        return $this;
    }
1303039
public static function queue($address, $subject, $content, $userId = null)
    {
        try {
            $email = new static;
            $email->user_id = $userId;
            $email->email = $address;
            $email->subject = $subject;
            $email->content = $content;
            $email->status = self::STATUS_PENDING;
            $email->attempt = 0;
            return $email->save();
        } catch (Exception $e) {
            Log::error($e->getMessage(), null, __METHOD__);
        }
        return false;
    }
697990
public function bcc($emails)
    {
        if (is_array($emails)) {
            $this->bcc = $emails;
        } else {
            $this->bcc = (array) $emails;
        }

        return $this;
    }
1113077
public static function email($headers = array())
	{
		\bdk\Debug::getInstance()->setErrorCaller();
		$new = 'Email->send()';
		trigger_error('deprecated:  '.__FUNCTION__.'... use '.$new.' instead', E_USER_DEPRECATED);
		$email = new Email(self::$cfgStatic);
		$return = $email->send($headers);
		return $return;
	}
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);
    }
1027140
public function synchronise(Subscription $subscription)
    {
        try {
            $contact = [
                'update' => true,
                'purge' => false,
                'contact' => [
                    'externalId' => $subscription->getId(),
                    'properties' => [
                        'email' => $subscription->getEmail(),
                    ],
                ],
            ];

            $response = $this->post('contact', $contact);

            if ($response->getStatusCode() == '204') { //Contact added successfully status code
                $this->subscriptionManager->updateStatus($subscription, Subscription::STATUS_SYNCED);

                return true;
            } else {
                $this->subscriptionManager->updateStatus($subscription, Subscription::STATUS_FAILED);

                return false;
            }
        } catch (\Exception $e) {
            $this->subscriptionManager->updateStatus($subscription, Subscription::STATUS_FAILED);

            return true;
        }
    }
1161127
public function checkEmail($seq = 0)
    {
        $action = "check_email";
        $options = array(
            'seq' => $seq,
            'sid_token' => $this->sid_token
        );

        return $this->client->get($action, $options);
    }
1298625
protected function isUsingQueue()
    {
        // It impossible to get either the email is sent out straight away
        // when the mailer is only push to queue, in this case we should
        // assume that sending is successful when using queue.

        $queue = false;
        $driver = 'mail';

        if ($this->memory instanceof Provider) {
            $queue = $this->memory->get('email.queue', false);
            $driver = $this->memory->get('email.driver');
        }

        return $queue || \in_array($driver, ['mailgun', 'mandrill', 'log']);
    }