Skip to content

Commit 87b11ef

Browse files
committed
Merge branch '4.4'
* 4.4: Replace SwiftMailer with the new Mailer Component
2 parents aeeef55 + c82bee0 commit 87b11ef

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

components/messenger.rst

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -200,23 +200,26 @@ Your own Sender
200200

201201
Imagine that you already have an ``ImportantAction`` message going through the
202202
message bus and being handled by a handler. Now, you also want to send this
203-
message as an email.
203+
message as an email (using the :doc:`Mime </components/mime>` and
204+
:doc:`Mailer </components/mailer>` components).
204205

205206
Using the :class:`Symfony\\Component\\Messenger\\Transport\\Sender\\SenderInterface`,
206207
you can create your own message sender::
207208

208209
namespace App\MessageSender;
209210

210211
use App\Message\ImportantAction;
212+
use Symfony\Component\Mailer\MailerInterface;
211213
use Symfony\Component\Messenger\Envelope;
212214
use Symfony\Component\Messenger\Transport\Sender\SenderInterface;
215+
use Symfony\Component\Mime\Email;
213216

214217
class ImportantActionToEmailSender implements SenderInterface
215218
{
216219
private $mailer;
217220
private $toEmail;
218221

219-
public function __construct(\Swift_Mailer $mailer, string $toEmail)
222+
public function __construct(MailerInterface $mailer, string $toEmail)
220223
{
221224
$this->mailer = $mailer;
222225
$this->toEmail = $toEmail;
@@ -231,12 +234,10 @@ you can create your own message sender::
231234
}
232235

233236
$this->mailer->send(
234-
(new \Swift_Message('Important action made'))
235-
->setTo($this->toEmail)
236-
->setBody(
237-
'<h1>Important action</h1><p>Made by '.$message->getUsername().'</p>',
238-
'text/html'
239-
)
237+
(new Email())
238+
->to($this->toEmail)
239+
->subject('Important action made')
240+
->html('<h1>Important action</h1><p>Made by '.$message->getUsername().'</p>')
240241
);
241242

242243
return $envelope;

0 commit comments

Comments
 (0)