微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如何解决允许在 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 举报,一经查实,本站将立刻删除。