Skip to content
This repository has been archived by the owner on Feb 6, 2022. It is now read-only.

Two mailers share the same auth handler #73

Closed
rolandow opened this issue Feb 19, 2014 · 3 comments
Closed

Two mailers share the same auth handler #73

rolandow opened this issue Feb 19, 2014 · 3 comments

Comments

@rolandow
Copy link

I am trying to use two different mailers from my console command. The problem is that the username / password seems to be overwritten. I checked on #symfony IRC where I was told that they apparently share the same auth handler.

I wrote a MailHandler with this service config:

mailhandler:
    class: %mailhandler.class%
    arguments: [@logger, @swiftmailer.mailer.local_mailer, @swiftmailer.mailer.sendgrid_mailer]

My swiftmailer config is as follows:

swiftmailer:
    default_mailer: local_mailer
    mailers:

        sendgrid_mailer:
            transport: smtp
            host: smtp.sendgrid.net
            port: 587
            encryption: ~
            username: xxx
            password: xxx
            antiflood:
                threshold: 99
                sleep: 2

        local_mailer:
            transport: smtp
            host: 127.0.0.1
            port: 587
            encryption: ~
            username: null
            password: null
            antiflood:
                threshold: 99
                sleep: 2

Now when I log some stuff in my MailHandler:

    public function __construct($logger, $measureMailer, $sendGridMailer) {
        $this->logger = $logger;

        $this->measureMailer = $measureMailer;
        $this->logger->debug("Measuremail host: ".$this->measureMailer->getTransport()->getHost()." user: ".$this->measureMailer->getTransport()->getUsername());

        $this->sendGridMailer = $sendGridMailer;
        $this->logger->debug("Sendgrid host: ".$this->sendGridMailer->getTransport()->getHost()." user: ".$this->sendGridMailer->getTransport()->getUsername());


        echo "var dump";
        var_dump($this->measureMailer->getTransport()->getUsername() === $this->sendGridMailer->getTransport()->getUsername());
    }

It seems that the username / password is always the one from the last mailer. The host names do differ though, having 127.0.0.1 and smtp.sendgrid.net as their values.

Also note that the code is being executed from a console script that extends from ContainerAwareCommand. When I test this in a normal controller, I don't have any issues. The username/password are different then (as they should).

By testing in a normal controller, I mean a controller that handles a HTTP request.. I wrote this little test:

    /**
     * @Route("/mail", name="_test_mail")
     */
    public function mailAction() {
        $mailer = $this->container->get('swiftmailer.mailer.sendgrid_mailer');
        echo "Sendgrid user: ".$mailer->getTransport()->getUsername();


        $mailer = $this->container->get('swiftmailer.mailer.local_mailer');
        echo "Local user: ".$mailer->getTransport()->getUsername();
        return new Response("Nou doei");
    }
@xabbuh
Copy link
Member

xabbuh commented Feb 19, 2014

As far as I can see all SMTP transports share the same auth handler (see lines 125-135 in the DI extension class).

@sstok
Copy link

sstok commented Feb 19, 2014

#70

@fabpot
Copy link
Member

fabpot commented Mar 14, 2014

Closing as it has been fixed in Swiftmailerbundle now.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants