通过python不用SMTP使用gmail
截至5月30日,不再接受SMTP。
制作简单的Python电子邮件器而不是使用“使用Google登录”选项的完整应用程序的新方法是什么?
鉴于我已经诊断出该问题并要求替代方法,因此不确定为什么要要求我进行代码和错误。 这里是。这是一个方便的电子邮件机,我在家工作时向我发短信给我锻炼。
import time
import smtplib
import random
gmail_user = '[email protected]'
gmail_password = 'TheCorrectPassword'
sent_from = gmail_user
to = ['[email protected]']
exercises = ['push ups', 'jumps in place', '20lb curls', 'tricep extensions', 'quarter mile runs']
levels = [1, 2, 3]
level1 = ['10', '15', '16', '20', '1']
level2 = ['15', '30', '30', '40', '2']
level3 = ['20', '50', '48', '70', '4']
while True:
if int(time.strftime('%H')) > 9:
if int(time.strftime('%H')) < 23:
abc = random.uniform(0, 1)
picker = random.randint(0, 4)
if abc < 0.3:
level = level1
if 0.3 < abc and abc < 0.8:
level = level2
if abc > 0.8:
level = level3
exersize = exercises[picker]
amount = level[picker]
try:
subject = f'Test'
body = f'Do {amount} {exersize}'
server = smtplib.SMTP_SSL('smtp.gmail.com', 465)
server.ehlo()
server.login(gmail_user, gmail_password)
server.sendmail(sent_from, to, body)
server.close()
print('Email sent!')
except Exception as error:
print(error)
time.sleep(random.randint(1500, 4800))
time.sleep(100)
错误:
(535,b'5.7.8不接受的用户名和密码。在\ n5.7.8 https://support.google.com/mail/?p=badcredentials JJ1-20020A17090303048100B00163247B64B64BFSM76555137PLB.115 -GSMTP '115 -GSMTP')
somtp for App saspes sopps passects。 可以在此处找到应用程序密码创建步骤,但是您必须先启用2个因子Auth,然后才能创建应用程序密码。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
2022年5月30日之后进行更正,发送用户实际密码不再被Google SMTP服务器接受,
您应该配置应用程序密码这起作用。然后用此新应用程序密码替换代码中的密码。
这通常是由于用户启用了2FA。
另一个选项是使用 xoauth22 。
Correction after May 30 2022, sending the users actual password is no longer accepted by googles smtp server
You should configuring an apps password this works. Then replace the password in your code with this new apps password.
This is normally due to the user having 2fa enabled.
Another option would be to use Xoauth2.