Sending e-mails securely with TLS

TLS protocol is a successor of SSL or Secure Socket Layer. This ensures that the communication between the client and the server is secure. This is done by sending the message in an encrypted format so that unauthorized people cannot see the message. It is not difficult to use TLS with smtplib. After you create an SMTP session object, you need to call the starttls() method. Before sending an e-mail, you need to login to the server by using the SMTP server credentials.

Here is an example for the second e-mail client:

#!/usr/bin/env python3 # Listing 2 import getpass import smtplib from email.mime.image import MIMEImage from email.mime.multipart import MIMEMultipart from email.mime.text import MIMEText SMTP_SERVER ...

Get Learning Python Network Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.