When run from inside controller and when in-memory spooling is configured via spool: { type: memory }
swiftmailer seems to work like this:
- whenever from within controller
mailer->send($message)
is called -> save message in memory - when controller has finished work and symfony Kernel is about to shutdown (somwehere in event
kernel.terminate
or smth) - check messages saved in memory and _actually submit them to SMTP-server
However this last step seems to silently ignore any errors which may be thrown when peforming submitting of the message to the SMTP server.
I discovered that errors are silently swallowed when I was setting up SMTP from Amazon SES, and have made wrong configuration:
mailer_transport: smtp
# For illustration I put WRONG port 9999, which means that this should trigger
# error (correct port would be 587)
mailer_port: 9999
mailer_encryption: tls
mailer_host: email-smtp.us-east-1.amazonaws.com
mailer_user: SES_USER_KEY
mailer_password: SES_USER_SECRET
Now, if I attempt to send email using wrong configuration from a symfony Command, just as expected I get Swift_TransportException
and error is NOT silently ignored. (From my observations it seems that symfony commands do NOT use memory-spooling and attempt to send messages immediately)
Below is sample of the command (so you're sure I am doing it right).
protected function execute(InputInterface $input, OutputInterface $output) {
$email = $input->getArgument('email');
$content = $this->getHelper('dialog')->ask($output, 'Please input content:');
$emsg = \Swift_Message::newInstance();
$emsg->setTo($email);
$emsg->setFrom('d@my-ses-verified-domain.com');
$emsg->setSubject('This is subject');
$emsg->setBody($content);
$this->getContainer()->get('mailer')->send($emsg);
}
And here's command output when the exception Swift_TransportException
is thrown:
ubuntu@localhost:~/my-app$ console acme:email:send existing@email.com
We are going to send email to :existing@email.com
Please input content:asdf adf
[Swift_TransportException]
Connection could not be established with host email-smtp.us-east-1.amazonaws.com [Connection timed out #110]
Hovewer if I attempt to send email from controller, then I see no error messages. Basically this means that in case there's an error (misconfiguration or network error or SMTP server down), all the emails I sent will silently disappear without any trace (no exception thrown, no error loggged in dev.log
neither in prod.log
).
How can I force Swiftmailer
to leave trace of failed delivery attempt?