symfony / swiftmailer-bundle

Symfony Swiftmailer Bundle
https://symfony.com/swiftmailer-bundle
MIT License
1.56k stars 151 forks source link

Service @mailer doesn't send email #206

Closed rsaenen closed 6 years ago

rsaenen commented 6 years ago

Hi, According to these documentation:
https://symfony.com/doc/current/email.html
https://swiftmailer.symfony.com/docs/sending.html

Using the Symfony service @mailer with the following configuration:

swiftmailer:
    transport: smtp
    auth_mode: login
    host: SSL0.OVH.NET
    encryption: ssl
    port: 465
    username: admin@mydomain.fr
    password: myverystrongpassword
    spool: { type: memory }

I dumped errors when I call $mailer->send($message, $errors); and don't get any errors.
However no email is sent...
When I don't use the Symfony service, the email is sent:

$transport = (new \Swift_SmtpTransport('SSL0.OVH.NET', 465, 'ssl'))
    ->setUsername('admin@mydomain.fr')
    ->setPassword('myverystrongpassword');

$mailer = new \Swift_Mailer($transport);

$mailer->send($message, $errors); // OK
$this->mailer->send($message, $errors); // KO

I searched for many configurations and still don't get why the service doesn't send the email...

dkop commented 6 years ago

I discovered this problem today. Swiftmailer bundle was updated from 2.3.11 to 2.6.3. The problem is in EmailSenderListener.php line 53.

if (method_exists($this->container, 'initialized') ? $this->container->initialized(sprintf('swiftmailer.mailer.%s', $name)) : true) {

I can't understand, why checking of initialization is needed here. Maybe, according to this commit https://github.com/symfony/swiftmailer-bundle/commit/05b925e761be2107e2e02073f7df8ee5c952e79c it is only for performance purposes, but i think, before that commit code

$this->container instanceof IntrospectableContainerInterface

always returned false and checking of initialization always passed and email messages was sent correct. Quick fix somewhere in code just initialize all mailers, for example:

foreach ($this->getContainer()->getParameter('swiftmailer.mailers') as $name) {
    $this->getContainer()->get($name);
}
rsaenen commented 6 years ago

Interesting ! I forgot to mention I use swiftmailer/swiftmailer (v5.4.8) and symfony/swiftmailer-bundle (v2.6.7).

dkop commented 6 years ago

In my case problem was that i used Swift_Transport instead Swift_Mailer to send messages. But i still don't understand, why messages had send before upgrading swiftmailer-bundle.

rsaenen commented 6 years ago

I'm still facing this issue with "symfony/swiftmailer-bundle": "^3.1", your merge hasn't been released ? @dkop do you use mailer with the yaml configuration?

dkop commented 6 years ago

Try to turn off spooler. Your code without swiftmailer-bundle don't use it. Try to update swiftmailer itself (not bundle).

rsaenen commented 6 years ago

Fixed with symfony/swiftmailer-bundle": "3.2 :1st_place_medal:

Moreover, I found that my SMTP filtered mail which contains link with a different domain that my SMTP email domain.