允许在 python 脚本中连接到 gmail 帐户

问题描述

我正在尝试使用 python 脚本发送电子邮件,如下所示:

import smtplib,ssl

port = 465  
smtp_server = "smtp.gmail.com"
sender_email = "my@gmail.com" 
receiver_email = "receiver@gmail.com" 
password = "123456"
message = """\
Subject: Hi there
This message is sent from Python."""

context = ssl.create_default_context()
with smtplib.SMTP_SSL(smtp_server,port,context=context) as server:
    server.login(sender_email,password)
    server.sendmail(sender_email,receiver_email,message) 

但不幸的是,Gmail 阻止了此连接,在运行此代码后,我收到一封电子邮件,说有人试图从非 Google 拥有的应用访问我的帐户,有人知道此问题的解决方案吗?

解决方法

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

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

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