在 python 中使用 google SMTP 发送电子邮件
sending email with google SMTP in python
您好,我正在尝试通过 google SMTP
在 python 中发送电子邮件
我认为代码是正确的,但我收到以下异常..
"G:\Installed Applications\Python\Python35-32\python.exe" "C:/Users/brand/Desktop/Test Projects/Python Projects/SMTP.py"
Traceback (most recent call last):
File "C:/Users/brand/Desktop/Test Projects/Python Projects/SMTP.py", line 22, in <module>
server.login(sender, password)
File "G:\Installed Applications\Python\Python35-32\lib\smtplib.py", line 730, in login
raise last_exception
File "G:\Installed Applications\Python\Python35-32\lib\smtplib.py", line 721, in login
initial_response_ok=initial_response_ok)
File "G:\Installed Applications\Python\Python35-32\lib\smtplib.py", line 627, in auth
initial_response = (authobject() if initial_response_ok else None)
File "G:\Installed Applications\Python\Python35-32\lib\smtplib.py", line 664, in auth_login
raise SMTPAuthenticationError(code, resp)
smtplib.SMTPAuthenticationError: (502, b'5.5.1 Unrecognized command. m16sm36193099wmb.13 - gsmtp')
Process finished with exit code 1
我的代码显示在这里:
import smtplib
sender = 'myEmail@gmail.com' # will be replaced with my real email address
password = 'mypassword' # will be replaced with my real password
receivers = ['yourEmail@gmail.com']
message = """From: DaftPunk <myEmail@gmail.com>
To: BlueStar <yourEmail@gmail.com>
MIME-Version: 1.0
Content-Type: text/html
Subject: Test E-Mail
Please visit this new website
<a href="http://www.google.com">http://www.google.com</a>
"""
server = smtplib.SMTP('smtp.gmail.com:587')
server.ehlo()
server.starttls()
server.login(sender, password) # Exception here
try:
server.sendmail(sender, receivers, message)
print("Message sent successfully")
except:
print("Failed to send message")
server.quit()
谁能解释一下哪里出了问题或我遗漏了什么?
找到解决方法了,代码没有问题
这是 Google 邮件中的安全问题 ..
我关注了这个 link
并打开对安全性较低的应用程序的访问,现在该脚本非常有用! :)
参考:Allowing less secure apps to access your account - Account Help
您好,我正在尝试通过 google SMTP
在 python 中发送电子邮件
我认为代码是正确的,但我收到以下异常..
"G:\Installed Applications\Python\Python35-32\python.exe" "C:/Users/brand/Desktop/Test Projects/Python Projects/SMTP.py"
Traceback (most recent call last):
File "C:/Users/brand/Desktop/Test Projects/Python Projects/SMTP.py", line 22, in <module>
server.login(sender, password)
File "G:\Installed Applications\Python\Python35-32\lib\smtplib.py", line 730, in login
raise last_exception
File "G:\Installed Applications\Python\Python35-32\lib\smtplib.py", line 721, in login
initial_response_ok=initial_response_ok)
File "G:\Installed Applications\Python\Python35-32\lib\smtplib.py", line 627, in auth
initial_response = (authobject() if initial_response_ok else None)
File "G:\Installed Applications\Python\Python35-32\lib\smtplib.py", line 664, in auth_login
raise SMTPAuthenticationError(code, resp)
smtplib.SMTPAuthenticationError: (502, b'5.5.1 Unrecognized command. m16sm36193099wmb.13 - gsmtp')
Process finished with exit code 1
我的代码显示在这里:
import smtplib
sender = 'myEmail@gmail.com' # will be replaced with my real email address
password = 'mypassword' # will be replaced with my real password
receivers = ['yourEmail@gmail.com']
message = """From: DaftPunk <myEmail@gmail.com>
To: BlueStar <yourEmail@gmail.com>
MIME-Version: 1.0
Content-Type: text/html
Subject: Test E-Mail
Please visit this new website
<a href="http://www.google.com">http://www.google.com</a>
"""
server = smtplib.SMTP('smtp.gmail.com:587')
server.ehlo()
server.starttls()
server.login(sender, password) # Exception here
try:
server.sendmail(sender, receivers, message)
print("Message sent successfully")
except:
print("Failed to send message")
server.quit()
谁能解释一下哪里出了问题或我遗漏了什么?
找到解决方法了,代码没有问题
这是 Google 邮件中的安全问题 ..
我关注了这个 link
并打开对安全性较低的应用程序的访问,现在该脚本非常有用! :)
参考:Allowing less secure apps to access your account - Account Help