dolibarr/htdocs/includes/swiftmailer/lib/classes/Swift/Mailer.php

99 lines
2.5 KiB
PHP
Raw Normal View History

2016-04-16 18:15:03 +02:00
<?php
/*
* This file is part of SwiftMailer.
* (c) 2004-2009 Chris Corbyn
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
* Swift Mailer class.
*
* @author Chris Corbyn
*/
class Swift_Mailer
{
/** The Transport used to send messages */
2018-01-21 15:55:56 +01:00
private $transport;
2016-04-16 18:15:03 +02:00
/**
* Create a new Mailer using $transport for delivery.
*/
public function __construct(Swift_Transport $transport)
{
2018-01-21 15:55:56 +01:00
$this->transport = $transport;
2016-04-16 18:15:03 +02:00
}
/**
* Create a new class instance of one of the message services.
*
* For example 'mimepart' would create a 'message.mimepart' instance
*
* @param string $service
*
* @return object
*/
public function createMessage($service = 'message')
{
return Swift_DependencyContainer::getInstance()
->lookup('message.'.$service);
}
/**
* Send the given Message like it would be sent in a mail client.
*
* All recipients (with the exception of Bcc) will be able to see the other
* recipients this message was sent to.
*
* Recipient/sender data will be retrieved from the Message object.
*
* The return value is the number of recipients who were accepted for
* delivery.
*
2021-12-07 17:11:34 +01:00
* @param array $failedRecipients An array of failures by-reference
2016-04-16 18:15:03 +02:00
*
2018-01-21 15:55:56 +01:00
* @return int The number of successful recipients. Can be 0 which indicates failure
2016-04-16 18:15:03 +02:00
*/
2018-01-21 15:55:56 +01:00
public function send(Swift_Mime_SimpleMessage $message, &$failedRecipients = null)
2016-04-16 18:15:03 +02:00
{
$failedRecipients = (array) $failedRecipients;
2021-12-07 17:11:34 +01:00
// FIXME: to be removed in 7.0 (as transport must now start itself on send)
2018-01-21 15:55:56 +01:00
if (!$this->transport->isStarted()) {
$this->transport->start();
2016-04-16 18:15:03 +02:00
}
$sent = 0;
try {
2018-01-21 15:55:56 +01:00
$sent = $this->transport->send($message, $failedRecipients);
2016-04-16 18:15:03 +02:00
} catch (Swift_RfcComplianceException $e) {
foreach ($message->getTo() as $address => $name) {
$failedRecipients[] = $address;
}
}
return $sent;
}
/**
* Register a plugin using a known unique key (e.g. myPlugin).
*/
public function registerPlugin(Swift_Events_EventListener $plugin)
{
2018-01-21 15:55:56 +01:00
$this->transport->registerPlugin($plugin);
2016-04-16 18:15:03 +02:00
}
/**
* The Transport used to send messages.
*
* @return Swift_Transport
*/
public function getTransport()
{
2018-01-21 15:55:56 +01:00
return $this->transport;
2016-04-16 18:15:03 +02:00
}
}