(self, keyfile=None, certfile=None, context=None)
return (resp, reply)
Puts the connection to the SMTP server into TLS mode.

        If there has been no previous EHLO or HELO command this session, this
        method tries ESMTP EHLO first.

        If the server supports TLS, this will encrypt the rest of the SMTP
        session. If you provide the keyfile and certfile parameters,
        the identity of the SMTP server and client can be checked. This,
        however, depends on whether the socket module really checks the
        certificates.

        This method may raise the following exceptions:

         SMTPHeloError            The server didn't reply properly to
                                  the helo greeting.
Puts the connection to the SMTP server into TLS mode.
Puts the connection to the SMTP server into TLS mode .
def starttls(self, keyfile=None, certfile=None, context=None):
        """Puts the connection to the SMTP server into TLS mode.

        If there has been no previous EHLO or HELO command this session, this
        method tries ESMTP EHLO first.

        If the server supports TLS, this will encrypt the rest of the SMTP
        session. If you provide the keyfile and certfile parameters,
        the identity of the SMTP server and client can be checked. This,
        however, depends on whether the socket module really checks the
        certificates.

        This method may raise the following exceptions:

         SMTPHeloError            The server didn't reply properly to
                                  the helo greeting.
        """
        self.ehlo_or_helo_if_needed()
        if not self.has_extn("starttls"):
            raise SMTPNotSupportedError(
                "STARTTLS extension not supported by server.")
        (resp, reply) = self.docmd("STARTTLS")
        if resp == 220:
            if not _have_ssl:
                raise RuntimeError("No SSL support included in this Python")
            if context is not None and keyfile is not None:
                raise ValueError("context and keyfile arguments are mutually "
                                 "exclusive")
            if context is not None and certfile is not None:
                raise ValueError("context and certfile arguments are mutually "
                                 "exclusive")
            if keyfile is not None or certfile is not None:
                import warnings
                warnings.warn("keyfile and certfile are deprecated, use a "
                              "custom context instead", DeprecationWarning, 2)
            if context is None:
                context = ssl._create_stdlib_context(certfile=certfile,
                                                     keyfile=keyfile)
            self.sock = context.wrap_socket(self.sock,
                                            server_hostname=self._host)
            self.file = None
            # RFC 3207:
            # The client MUST discard any knowledge obtained from
            # the server, such as the list of SMTP service extensions,
            # which was not obtained from the TLS negotiation itself.
            self.helo_resp = None
            self.ehlo_resp = None
            self.esmtp_features = {}
            self.does_esmtp = False
        else:
            # RFC 3207:
            # 501 Syntax error (no parameters allowed)
            # 454 TLS not available due to temporary reason
            raise SMTPResponseException(resp, reply)
        return (resp, reply)
def starttls ( self , keyfile = None , certfile = None , context = None ) : self . ehlo_or_helo_if_needed ( ) if not self . has_extn ( "starttls" ) : raise SMTPNotSupportedError ( "STARTTLS extension not supported by server." ) ( resp , reply ) = self . docmd ( "STARTTLS" ) if resp == 220 : if not _have_ssl : raise RuntimeError ( "No SSL support included in this Python" ) if context is not None and keyfile is not None : raise ValueError ( "context and keyfile arguments are mutually " "exclusive" ) if context is not None and certfile is not None : raise ValueError ( "context and certfile arguments are mutually " "exclusive" ) if keyfile is not None or certfile is not None : import warnings warnings . warn ( "keyfile and certfile are deprecated, use a " "custom context instead" , DeprecationWarning , 2 ) if context is None : context = ssl . _create_stdlib_context ( certfile = certfile , keyfile = keyfile ) self . sock = context . wrap_socket ( self . sock , server_hostname = self . _host ) self . file = None # RFC 3207: # The client MUST discard any knowledge obtained from # the server, such as the list of SMTP service extensions, # which was not obtained from the TLS negotiation itself. self . helo_resp = None self . ehlo_resp = None self . esmtp_features = { } self . does_esmtp = False else : # RFC 3207: # 501 Syntax error (no parameters allowed) # 454 TLS not available due to temporary reason raise SMTPResponseException ( resp , reply ) return ( resp , reply )