Sending email from Python using STARTTLS
问题 I want to send emails with a Python script by using Python's smtplib. The script should only send the email, if an encrypted connection to the server can be established. To encrypt the connection to port 587 I want to use STARTTLS. Using some examples I have written the following code: smtp_server = smtplib.SMTP(host, port=port) context = ssl.create_default_context() smtp_server.starttls(context) smtp_server.login(user, password) smtp_server.send_message(msg) msg, host, port, user, password