I have a Linux server with SMTP relay configured. Using the command "mail test@test.com" it works but when I use SwiftMailerBundle, no mail is sent.
Logs :
[2014-03-14 10:01:06] event.DEBUG: Notified event "console.command" to listener "Symfony\Bridge\Monolog\Handler\ConsoleHandler::onCommand". [] []
[2014-03-14 10:01:06] event.DEBUG: Notified event "console.terminate" to listener "Symfony\Bridge\Monolog\Handler\ConsoleHandler::onTerminate". [] []
[2014-03-14 10:01:06] event.DEBUG: Notified event "console.terminate" to listener "Symfony\Bundle\SwiftmailerBundle\EventListener\EmailSenderListener::onTerminate". [] []
Parameters.yml :
mailer_transport: mail
mailer_host: localhost
mailer_user: myusername
mailer_password: ********
My command :
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
class AbsenceCommand extends ContainerAwareCommand
{
protected function configure()
{
$this
->setName('absence:absence')
->setDescription('Envoi des absences aux parents')
;
}
protected function execute(InputInterface $input, OutputInterface $output)
{
$message = \Swift_Message::newInstance()
->setSubject('Hello Email')
->setFrom('noreply@test.com')
->setTo('mymail@test.com')
->setBody("Test")
;
$this->getContainer()->get('mailer')->send($message);
$mailer = $this->getContainer()->get('mailer');
$transport = $mailer->getTransport();
if ($transport instanceof \Swift_Transport_SpoolTransport) {
$spool = $transport->getSpool();
$sent = $spool->flushQueue($this->getContainer()->get('swiftmailer.transport.real'));
}
$output->writeln("E-mail envoyé aux parents des apprentis !");
}
}
Do you have any idea on the solution ?
Regards !
try to install postfix mail server. use this command to install postfix:sudo apt-get install postfix
I believe it's because of the mailer_transport: parameter value. try setting it to mailer_transport: smtp .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.