Gmail 阻止通过 python 登录

问题描述

我使用flask创建了一个网站,它会询问用户的电子邮件ID和体重,按下提交按钮后,用户将收到包含他/她个人体重以及所有条目平均值的邮件。 但是,Gmail 已阻止从我的 id(发件人的 id)发送邮件,即使在我允许不太安全的应用程序之后,它也表明它是可疑的。 前几次运行良好,直到我将它推送到实时服务器上,现在它甚至在 localhost 上也显示相同。 这是我用于发送自动邮件代码

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,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)

然而,代码可以很好地接收输入,因为它将输入存储在数据库中(我将其设置为在成功时存储)

enter image description here

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)