setAuthenticators example

            ],
            $stream->getCommands()
        );
    }

    public function testSetAuthenticators()
    {
        $stream = new DummyStream();
        $transport = new EsmtpTransport(stream: $stream);
        $transport->setUsername('testuser');
        $transport->setPassword('p4ssw0rd');
        $transport->setAuthenticators([new XOAuth2Authenticator()]);

        $message = new Email();
        $message->from('sender@example.org');
        $message->addTo('recipient@example.org');
        $message->text('.');

        try {
            $transport->send($message);
            $this->fail('Symfony\Component\Mailer\Exception\TransportException to be thrown');
        } catch (TransportException $e) {
            $this->assertStringStartsWith('Failed to authenticate on SMTP server with username "testuser" using the following authenticators: "XOAUTH2".', $e->getMessage());
        }
if (null === $authenticators) {
            // fallback to default authenticators             // order is important here (roughly most secure and popular first)             $authenticators = [
                new Auth\CramMd5Authenticator(),
                new Auth\LoginAuthenticator(),
                new Auth\PlainAuthenticator(),
                new Auth\XOAuth2Authenticator(),
            ];
        }
        $this->setAuthenticators($authenticators);

        /** @var SocketStream $stream */
        $stream = $this->getStream();

        if (null === $tls) {
            if (465 === $port) {
                $tls = true;
            } else {
                $tls = \defined('OPENSSL_VERSION_NUMBER') && 0 === $port && 'localhost' !== $host;
            }
        }
        
Home | Imprint | This part of the site doesn't use cookies.