我正在嘗試使用 python 發送電子郵件。在 Google 禁用“不太安全的應用程式”之前,我的代碼運行良好。我的電子郵件地址和密碼都是正確的。
server = smtplib.SMTP_SSL("smtp.gmail.com", 465)
serverEmail = "EMAILADDRESS"
serverPw = "QWERTY"
server.login(serverEmail, serverPw)
subject = "Rejection"
body = "Hi! You've been unfortunately declined access to our system."
message = f'Subject: {subject}\n\n{body}'
server.sendmail("EMAILADDRESS", doctorEmail['email'], message)
server.quit()
我現在收到此錯誤:
smtplib.SMTPAuthenticationError: (535, b'5.7.8 用戶名和密碼不被接受。
使用時出現此錯誤server.starttls():
smtplib.SMTPNotSupportedError:服務器不支持 STARTTLS 擴展。
uj5u.com熱心網友回復:
這對我有用。您需要為此生成一個應用程式密碼。請參閱https://support.google.com/accounts/answer/185833?hl=en
import smtplib as smtp
connection = smtp.SMTP_SSL('smtp.gmail.com', 465)
email_addr = '[email protected]'
email_passwd = 'app_password_generated_in_Google_Account_Settings'
connection.login(email_addr, email_passwd)
connection.sendmail(from_addr=email_addr, to_addrs='[email protected]', msg="Sent from my IDE. Hehe")
connection.close()
出于某種原因,我所有的電子郵件都在收件人帳戶的垃圾郵件檔案夾中結束。
uj5u.com熱心網友回復:
谷歌在 6 月 2 日暫時禁用了“不太安全的應用程式”的訪問,但在美國東部時間晚上 7 點左右,他們重新啟用了它。所以如果你只等了幾個小時,你就不需要做任何事情。
我懷疑他們不知何故受到了“意外后果法則”的影響,但如果他們在某個時候再次關閉此訪問權限,我不會感到驚訝。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/485654.html
上一篇:InternetExplorer的退役是否會扼殺InternetExplorer平臺API?
下一篇:在Powershell中運行wixExeCommand時出錯:無法識別術語“::SecurityProtocol”
