feat: add command to test smtp transport

This commit is contained in:
Björn Fromme
2025-01-23 17:42:00 +01:00
parent 1da50adf62
commit b27fd086ff
+43
View File
@@ -0,0 +1,43 @@
<?php
declare(strict_types=1);
namespace App\Command;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Mailer\MailerInterface;
use Symfony\Component\Mime\Email;
#[AsCommand(name: 'app:mail-test', description: 'Testing SMTP Transport')]
class MailTestCommand extends Command
{
public function __construct(private readonly MailerInterface $mailer)
{
parent::__construct();
}
protected function configure(): void
{
$this
->addArgument('to', InputArgument::REQUIRED, 'Recipient email')
->addArgument('from', InputArgument::OPTIONAL, 'Sender email', '[email protected]')
;
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
$email = (new Email())
->to($input->getArgument('to'))
->from($input->getArgument('from'))
->subject('Testing SMTP Transport')
->text('Testing SMTP Transport');
$this->mailer->send($email);
return Command::SUCCESS;
}
}