import smtplib
sender = '[email protected]'
receiver = ['[email protected]']
message = """From: From Person <[email protected]>
To: To Person <[email protected]>
Subject: SMTP e-mail test
This is a test e-mail message.
"""
try:
print("trying host and port...")
smtpObj = smtplib.SMTP('smtp.gmail.com', 465)
print("sending mail...")
smtpObj.sendmail(sender, receiver, message)
print("Succesfully sent email")
except SMTPException:
print("Error: unable to send email")
我創建了兩個新的電子郵件帳戶(上面),都在同一臺服務器(gmail)上進行測試。 它達到了打印「嘗試主機和端口...」的程度,並且不再進一步。所以問題應該是我輸入的地址和端口號。但根據Gmail的傳出郵件服務器的詳細信息,我已經正確地輸入了它們。任何想法有什麼不對?沒有使用smtplib發送電子郵件 - python
如果我刪除端口號或嘗試不同的端口號,如587我提供了一個錯誤。
啓用從'smtplib'診斷,所以你能看到它會錯了。在這個細節層面上,我們所能做的只是猜測。我的猜測是Gmail需要驗證,在這種情況下,請查看任何近乎重複的英國郵件。 – tripleee