使用Gmail Python发送电子邮件 [英] send email with Gmail Python
问题描述
我正在尝试发送电子邮件,但遇到此错误: smtplib.SMTPAuthenticationError:(534,需要b'5.7.9特定于应用程序的密码.有关详细信息,请参见\ n5.7.9 https://support.google.com/mail/?p=InvalidSecondFactor d2sm13023190qkl.98-gsmtp')
I am attempting to send an email, but I run into this error:
smtplib.SMTPAuthenticationError: (534, b'5.7.9 Application-specific password required. Learn more at\n5.7.9 https://support.google.com/mail/?p=InvalidSecondFactor d2sm13023190qkl.98 - gsmtp')
在网络URL中,我看不到任何超级有用的东西,有人会提出任何建议吗?为此,我将电子邮件帐户密码保留为 test
,而不是共享我的个人信息.
In the web URL i dont see anything super useful, would anyone have any tips? For SO purposes I left the email account passwords as test
versus sharing my person info..
import smtplib
import ssl
# User configuration
sender_email = 'test@gmail.com'
receiver_email = 'test@gmail.com'
password = 'test'
# Email text
email_body = '''
This is a test email sent by Python. Isn't that cool?
'''
# Creating a SMTP session | use 587 with TLS, 465 SSL and 25
server = smtplib.SMTP('smtp.gmail.com', 587)
# Encrypts the email
context = ssl.create_default_context()
server.starttls(context=context)
# We log in into our Google account
server.login(sender_email, password)
# Sending email from sender, to receiver with the email body
server.sendmail(sender_email, receiver_email, email_body)
print('Email sent!')
print('Closing the server...')
server.quit()
推荐答案
您必须在Google配置中允许安全性降低的应用程序".
You must allow the "Less secure apps" in Google configurations.
这是与此有关的另一个线程的链接:链接
Here is the link of another thread about it : Link
这篇关于使用Gmail Python发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!