public function authenticate(string $user, string $password = null): Generator
    {
        $response = yield from $this->sendCommand(new Command('AUTHINFO USER', $user));

        // Check if password is required.
        if ($response->code() === 381) {
            if ($password === null) {
                throw new \Exception("Password required");
            }

            yield from $this->sendCommand(new Command('AUTHINFO PASS', $password));
        }
    }