You want to just say EHLO before running straight into STARTTLS:
server = smtplib.SMTP('smtp.gmail.com:587')
server.ehlo()
server.starttls()
Additionally, you should make From:, To: and Subject: message headers, isolated from the message body by a clear line and use CRLF as EOL markers.
Example:
msg = "\r\n".join([
"From: [email protected]",
"To: [email protected]",
"Subject: Just a message",
"",
"Why, oh why"
])
Note:
With the goal for this to work you want to enable the "allow less secure applications" choice in your Gmail account configuration. Else you will get a "basic security alert" when Gmail identifies that a non-Google application is attempting to login to your account.
Interested to learn the concepts of Python in detail? Come and join the python course to gain more knowledge in Python
Watch this below video tutorial for more information