'Check for valid config, verify connectivity.'

def connection_is_valid(self):

    server = None
    try:
        server = self.connect()
    except smtplib.socket.gaierror:
        _LOGGER.exception('SMTP    server    not    found    (%s:%s).    Please    check    the    IP    address    or    hostname    of    your    SMTP    server', self._server, self._port)
        return False
    except (smtplib.SMTPAuthenticationError, ConnectionRefusedError):
        _LOGGER.exception('Login    not    possible.    Please    check    your    setting    and/or    your    credentials')
        return False
    finally:
        if server:
            server.quit()
    return True
