Class yii\symfonymailer\Mailer
Inheritance | yii\symfonymailer\Mailer » yii\mail\BaseMailer |
---|---|
Source Code | https://github.com/yiisoft/yii2-symfonymailer/blob/master/src/Mailer.php |
Public Properties
Property | Type | Description | Defined By |
---|---|---|---|
$enableMailerLogging | boolean | Whether to enable writing of the Mailer internal logs using Yii log mechanism. | yii\symfonymailer\Mailer |
$messageClass | string | Message default class name. | yii\symfonymailer\Mailer |
Public Methods
Method | Description | Defined By |
---|---|---|
getSymfonyMailer() | yii\symfonymailer\Mailer | |
getTransport() | yii\symfonymailer\Mailer | |
setTransport() | yii\symfonymailer\Mailer | |
withEncryptor() | Returns a new instance with the specified encryptor. | yii\symfonymailer\Mailer |
withSigner() | Returns a new instance with the specified signer. | yii\symfonymailer\Mailer |
Protected Methods
Method | Description | Defined By |
---|---|---|
sendMessage() | yii\symfonymailer\Mailer |
Property Details
Whether to enable writing of the Mailer internal logs using Yii log mechanism. If enabled Logger plugin will be attached to the transport for this purpose.
See also yii\symfonymailer\Logger.
Message default class name.
Method Details
public \Symfony\Component\Mailer\Mailer getSymfonyMailer ( ) | ||
return | \Symfony\Component\Mailer\Mailer |
Swift mailer instance |
---|
public function getSymfonyMailer(): SymfonyMailer
{
if (!is_object($this->symfonyMailer)) {
$this->symfonyMailer = $this->createSymfonyMailer();
}
return $this->symfonyMailer;
}
public \Symfony\Component\Mailer\Transport\TransportInterface getTransport ( ) |
public function getTransport(): TransportInterface
{
if (!is_object($this->_transport)) {
$this->_transport = $this->createTransport($this->_transport);
}
return $this->_transport;
}
protected void sendMessage ( $message ) | ||
$message | ||
throws | \Symfony\Component\Mailer\Exception\TransportExceptionInterface |
If sending failed. |
---|
protected function sendMessage($message): bool
{
if (!($message instanceof Message)) {
throw new RuntimeException(sprintf(
'The message must be an instance of "%s". The "%s" instance is received.',
Message::class,
get_class($message),
));
}
$message = $message->getSymfonyEmail();
if ($this->encryptor !== null) {
$message = $this->encryptor->encrypt($message);
}
if ($this->signer !== null) {
$message = $this->signer instanceof DkimSigner
? $this->signer->sign($message, $this->dkimSignerOptions)
: $this->signer->sign($message)
;
}
try {
$this->getSymfonyMailer()->send($message);
} catch (\Exception $exception) {
Yii::getLogger()->log($exception->getMessage(), \yii\log\Logger::LEVEL_ERROR, __METHOD__);
return false;
}
return true;
}
public void setTransport ( $transport ) | ||
$transport | array|\Symfony\Component\Mailer\Transport\TransportInterface | |
throws | \yii\base\InvalidConfigException |
on invalid argument. |
---|
public function setTransport($transport): void
{
if (!is_array($transport) && !$transport instanceof TransportInterface) {
throw new InvalidConfigException('"' . get_class($this) . '::transport" should be either object or array, "' . gettype($transport) . '" given.');
}
if ($transport instanceof TransportInterface) {
$this->_transport = $transport;
} elseif (is_array($transport)) {
$this->_transport = $this->createTransport($transport);
}
$this->symfonyMailer = null;
}
Returns a new instance with the specified encryptor.
See also https://symfony.com/doc/current/mailer.html#encrypting-messages.
public self withEncryptor ( \Symfony\Component\Mime\Crypto\SMimeEncrypter $encryptor ) | ||
$encryptor | \Symfony\Component\Mime\Crypto\SMimeEncrypter |
The encryptor instance. |
public function withEncryptor(SMimeEncrypter $encryptor): self
{
$new = clone $this;
$new->encryptor = $encryptor;
return $new;
}
Returns a new instance with the specified signer.
See also https://symfony.com/doc/current/mailer.html#signing-messages.
public self withSigner ( object $signer, array $options = [] ) | ||
$signer | \Symfony\Component\Mime\Crypto\DkimSigner|object|\Symfony\Component\Mime\Crypto\SMimeSigner |
The signer instance. |
$options | array |
The options for DKIM signer {@see \Symfony\Component\Mime\Crypto\DkimSigner}. |
throws | RuntimeException |
If the signer is not an instance of {@see \Symfony\Component\Mime\Crypto\DkimSigner} or {@see \Symfony\Component\Mime\Crypto\SMimeSigner}. |
---|
public function withSigner(object $signer, array $options = []): self
{
$new = clone $this;
if ($signer instanceof DkimSigner) {
$new->signer = $signer;
$new->dkimSignerOptions = $options;
return $new;
}
if ($signer instanceof SMimeSigner) {
$new->signer = $signer;
return $new;
}
throw new RuntimeException(sprintf(
'The signer must be an instance of "%s" or "%s". The "%s" instance is received.',
DkimSigner::class,
SMimeSigner::class,
get_class($signer),
));
}