0

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.

zx485
  • 28,498
  • 28
  • 50
  • 59
  • It is better to include your research about the related post and explaining why they don't meet your requirement. That is enough to avoid duplicate confusions. Welcome to Stack-overflow. – Munim Munna Mar 31 '18 at 21:01
  • I thought of doing so but it would take a lot of time then before anyone actually answers correctly. – user496119 Mar 31 '18 at 21:05
  • It is good practice to do so, one or 2 sentences to show you have done some searching before putting forward a question and let people understands why it is not a duplicate right away. – Munim Munna Mar 31 '18 at 21:14

0 Answers0