def open(self) -> bool:
        """
        Ensures we have a connection to the email server. Returns whether or
        not a new connection was required (True or False).
        """
        if self.connection:
            # Nothing to do if the connection is already open.
            return False

        connection_params = {'local_hostname': DNS_NAME.get_fqdn()}
        if self.timeout is not None:
            connection_params['timeout'] = self.timeout
        try:
            self.connection = smtplib.SMTP(self.host, self.port,
                                           **connection_params)

            # TLS
            context = ssl.SSLContext(self._protocol())
            if self.ssl_certfile:
                context.load_cert_chain(certfile=self.ssl_certfile,
                                        keyfile=self.ssl_keyfile)
            self.connection.ehlo()
            self.connection.starttls(context=context)
            self.connection.ehlo()
            if self.username and self.password:
                self.connection.login(self.username, self.password)
                log.debug("Successful SMTP connection/login")
            else:
                log.debug("Successful SMTP connection (without login)")
            return True
        except smtplib.SMTPException:
            log.debug("SMTP connection and/or login failed")
            if not self.fail_silently:
                raise
def open ( self ) -> bool : if self . connection : return False connection_params = { 'local_hostname' : DNS_NAME . get_fqdn ( ) } if self . timeout is not None : connection_params [ 'timeout' ] = self . timeout try : self . connection = smtplib . SMTP ( self . host , self . port , ** connection_params ) context = ssl . SSLContext ( self . _protocol ( ) ) if self . ssl_certfile : context . load_cert_chain ( certfile = self . ssl_certfile , keyfile = self . ssl_keyfile ) self . connection . ehlo ( ) self . connection . starttls ( context = context ) self . connection . ehlo ( ) if self . username and self . password : self . connection . login ( self . username , self . password ) log . debug ( "Successful SMTP connection/login" ) else : log . debug ( "Successful SMTP connection (without login)" ) return True except smtplib . SMTPException : log . debug ( "SMTP connection and/or login failed" ) if not self . fail_silently : raise
Ensures we have a connection to the email server. Returns whether or
        not a new connection was required (True or False).