SMTP.starttls(keyfile=None, certfile=None, context=None)
Put the SMTP connection in TLS (Transport Layer Security) mode. All SMTP commands that follow will be encrypted. You should then call ehlo() again.
If keyfile and certfile are provided, these are passed to the socket module’s ssl() function.
Optional context parameter is a ssl.SSLContext object; This is an alternative to using a keyfile and a certfile and if specified both keyfile and certfile should be None.
If there has been no previous EHLO or HELO command this session, this method tries ESMTP EHLO first.
-
SMTPHeloError - The server didn’t reply properly to the
HELOgreeting. -
SMTPNotSupportedError - The server does not support the STARTTLS extension.
-
RuntimeError - SSL/TLS support is not available to your Python interpreter.
Changed in version 3.3: context was added.
Changed in version 3.4: The method now supports hostname check with SSLContext.check_hostname and Server Name Indicator (see HAS_SNI).
Changed in version 3.5: The error raised for lack of STARTTLS support is now the SMTPNotSupportedError subclass instead of the base SMTPException.
Please login to continue.