I am trying to send a mail from python, but it shows
smtplib.SMTPNotSupportedError: STARTTLS extension not supported by server.
Here is my code:
from email.mime.text import MIMEText
import smtplib
def send_email(email):
from_email="mine@gmail.com"
from_password="xxxxx"
to_email=email
subject="Data"
message = "Hey there!!"
msg=MIMEText(message,'html')
msg['Subject']=subject
msg['To']=to_email
msg['From']=from_email
gmail=smtplib.SMTP('smtp.gmail.com',587)
gmail.connect('smtp.gmail.com',587)
gmail.ehlo()
gmail.starttls()
gmail.login(from_email,from_password)
gmail.sendmail(from_email,to_email,msg.as_string())
gmail.quit()
I've checked the less secure apps option in gmail so it should work fine but its not working. I've tried other suggestions like remove starttls()
command but nothing is working.
My question is not answered in any of the similar posts, so do look at it before marking it as duplicate.