Final Class Yiisoft\Mailer\Symfony\Mailer
| Inheritance | Yiisoft\Mailer\Symfony\Mailer » Yiisoft\Mailer\BaseMailer |
|---|
Mailer implements a mailer based on Symfony Mailer.
See also https://github.com/symfony/mailer.
Public Methods
| Method | Description | Defined By |
|---|---|---|
| __construct() | Yiisoft\Mailer\Symfony\Mailer | |
| withEncryptor() | Returns a new instance with the specified encryptor. | Yiisoft\Mailer\Symfony\Mailer |
| withSigner() | Returns a new instance with the specified signer. | Yiisoft\Mailer\Symfony\Mailer |
Protected Methods
| Method | Description | Defined By |
|---|---|---|
| sendMessage() | Yiisoft\Mailer\Symfony\Mailer |
Method Details
| public mixed __construct ( \Symfony\Component\Mailer\Transport\TransportInterface $transport, \Yiisoft\Mailer\MessageSettings|null $messageSettings = null, \Psr\EventDispatcher\EventDispatcherInterface|null $eventDispatcher = null ) | ||
| $transport | \Symfony\Component\Mailer\Transport\TransportInterface | |
| $messageSettings | \Yiisoft\Mailer\MessageSettings|null | |
| $eventDispatcher | \Psr\EventDispatcher\EventDispatcherInterface|null | |
public function __construct(
TransportInterface $transport,
?MessageSettings $messageSettings = null,
?EventDispatcherInterface $eventDispatcher = null,
) {
parent::__construct($messageSettings, $eventDispatcher);
$this->symfonyMailer = new SymfonyMailer($transport);
$this->emailFactory = new EmailFactory();
}
| protected sendMessage ( \Yiisoft\Mailer\MessageInterface $message ) | ||
| $message | \Yiisoft\Mailer\MessageInterface | |
| throws | \Symfony\Component\Mailer\Exception\TransportExceptionInterface |
If sending failed. |
|---|---|---|
protected function sendMessage(MessageInterface $message): void
{
$email = $this->emailFactory->create($message);
if ($this->encryptor !== null) {
$email = $this->encryptor->encrypt($email);
}
if ($this->signer !== null) {
$email = $this->signer instanceof DkimSigner
? $this->signer->sign($email, $this->dkimSignerOptions)
: $this->signer->sign($email)
;
}
$this->symfonyMailer->send($email);
}
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 ( \Symfony\Component\Mime\Crypto\DkimSigner|object|\Symfony\Component\Mime\Crypto\SMimeSigner $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,
$signer::class,
));
}
Signup or Login in order to comment.