截至5月30日,谷歌已取消了对不太安全的应用程序访问G-Mail的限制.我正在使用SMTP库从我的flask网站发送邮箱,由于这种方法需要Google刚刚删除的功能,我被卡住了.我正在寻找任何解决这个问题的方法或替代解决方案.

推荐答案

解决方案很简单,不需要太多更改:

  1. Turn on 2-Step Verification在你的谷歌帐户.这一步是required,因为谷歌只允许在启用了两步验证的帐户上为应用程序生成密码.
  2. 转到为你的应用程序生成应用程序密码(https://myaccount.google.com/apppasswords)和generate a password.

  1. 只需使用您的gmail用户名(your_mail@gmail.com)和python应用程序中生成的密码.

我已经用以下脚本测试了我刚才附加到您的内容:

import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
mail_content = '''
Hello Stack Overflow!!!
'''

sender_address = 'your_mail@gmail.com'
sender_pass = 'generated_password'
receiver_address = 'your_mail@gmail.com'

message = MIMEMultipart()
message['From'] = sender_address
message['To'] = receiver_address
message['Subject'] = 'A test mail sent by Python.'   

message.attach(MIMEText(mail_content, 'plain'))
session = smtplib.SMTP('smtp.gmail.com', 587)
session.starttls()
session.login(sender_address, sender_pass)
text = message.as_string()
session.sendmail(sender_address, receiver_address, text)
session.quit()
print('Mail Sent')

And it worked without problems: enter image description here

Python-3.x相关问答推荐

Python GUI:tkinter应用程序作为Windows的实时桌面

requests.exceptions.InvalidSchema:未找到连接适配器.我试图遍历一个列表

使用 multiprocessing 处理图像

如何在 Telethon 中向机器人发送发送表情符号

如何从形状汇总图中提取实际值

如何在 VSCode 的在 Cloud Run Emulator 上运行/调试构建设置中添加 SQL 连接

Pytorch:图像标签

Python - 使用 OpenCV 将字节图像转换为 NumPy 数组

在 Python 3.5 中使用 aiohttp 获取多个 url

ValueError:FixedLocator 位置的数量 (5),通常来自对 set_ticks 的调用,与刻度标签的数量 (12) 不匹配

如何判断一个字符串是否包含有效的 Python 代码

如何在 Python3 中添加带有标志的命令行参数?

如何等待 create_task() 创建的任务完成?

混合全局/参数和名为top的函数的奇怪python行为

从 IPython 重新加载 Python 扩展模块

如何在 Pandas 中的超 Big Data 框上创建数据透视表

Python 2 与 Python 3 - urllib 格式

有没有一种标准方法来确保 python 脚本将由 python2 而不是 python3 解释?

如何将发音相似的词放在一起

如何在 Python 3.4 中使用 pip 3?