MCPcopy Index your code
hub / github.com/python/cpython / starttls

Method starttls

Lib/smtplib.py:764–807  ·  view source on GitHub ↗

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 context paramete

(self, *, context=None)

Source from the content-addressed store, hash-verified

762 raise last_exception
763
764 def starttls(self, *, context=None):
765 """Puts the connection to the SMTP server into TLS mode.
766
767 If there has been no previous EHLO or HELO command this session, this
768 method tries ESMTP EHLO first.
769
770 If the server supports TLS, this will encrypt the rest of the SMTP
771 session. If you provide the context parameter,
772 the identity of the SMTP server and client can be checked. This,
773 however, depends on whether the socket module really checks the
774 certificates.
775
776 This method may raise the following exceptions:
777
778 SMTPHeloError The server didn't reply properly to
779 the helo greeting.
780 """
781 self.ehlo_or_helo_if_needed()
782 if not self.has_extn("starttls"):
783 raise SMTPNotSupportedError(
784 "STARTTLS extension not supported by server.")
785 (resp, reply) = self.docmd("STARTTLS")
786 if resp == 220:
787 if not _have_ssl:
788 raise RuntimeError("No SSL support included in this Python")
789 if context is None:
790 context = ssl._create_stdlib_context()
791 self.sock = context.wrap_socket(self.sock,
792 server_hostname=self._host)
793 self.file = None
794 # RFC 3207:
795 # The client MUST discard any knowledge obtained from
796 # the server, such as the list of SMTP service extensions,
797 # which was not obtained from the TLS negotiation itself.
798 self.helo_resp = None
799 self.ehlo_resp = None
800 self.esmtp_features = {}
801 self.does_esmtp = False
802 else:
803 # RFC 3207:
804 # 501 Syntax error (no parameters allowed)
805 # 454 TLS not available due to temporary reason
806 raise SMTPResponseException(resp, reply)
807 return (resp, reply)
808
809 def sendmail(self, from_addr, to_addrs, msg, mail_options=(),
810 rcpt_options=()):

Callers 2

emitMethod · 0.95
test_connect_starttlsMethod · 0.95

Calls 6

has_extnMethod · 0.95
docmdMethod · 0.95
wrap_socketMethod · 0.80

Tested by 1

test_connect_starttlsMethod · 0.76