Gmail blocking login through python

Viewed 180

I have created a website using flask in which it will ask user's email id and weight and after pressing the submit button user will receive mail containing his/her individual weight as well as average of all entries. However, Gmail has blocked sending mails from my id(sender's id) stating it to be suspicious even after i have ALLOWED LESS SECURE APPS. It worked fine for first few times until i pushed it on live server and now it is showing same on localhost even. Here is the code i used for sending automated mail:

from email.mime.text import MIMEText
import smtplib

def send_email(email,weight,avg_wt,ct):
    from_email= 'myemail@gmail.com'
    from_pw= 'mypaswd'
    to_email=email


    subject="Weight data"
    message="""Hi there,<br> 
            your weight is <b>%s</b> kgs.<br>
            And your average weight was found to be <b>%s</b> kgs.<br>
            This was calculated from <b>%s</b> entries <br>
            Thanks""" %(weight,avg_wt,ct)

    msg=MIMEText(message,'html')
    msg['Subject']=subject
    msg['To']=to_email
    msg['From']=from_email

    gmail=smtplib.SMTP('smtp.gmail.com',587)
    gmail.ehlo()
    gmail.starttls()
    gmail.login(from_email,from_pw)
    gmail.send_message(msg)

The code however is working fine for taking inputs as it is storing them in the database(which i conditioned it to store on success) enter image description here

0 Answers
Related