[英]Difficulty sending e-mail using python
我正在嘗試讓Python發送電子郵件。 首先,我如下啟動python smptd:
python -m smtpd -n -c DebuggingServer localhost:1025
然后,從https://www.tutorialspoint.com/python/python_sending_email.htm改編示例,我有以下腳本:
#!/usr/bin/python
import smtplib
sender = 'from@fromdomain.com'
receivers = ['brt381@gmail.com']
message = """From: From Person <from@fromdomain.com>
To: To Person <brt381@gmail.com>
Subject: SMTP e-mail test
This is a test e-mail message.
"""
try:
smtpObj = smtplib.SMTP('localhost:1025')
smtpObj.sendmail(sender, receivers, message)
print "Successfully sent email"
except SMTPException:
print "Error: unable to send email"
運行此腳本時,我收到消息“成功發送電子郵件”。 在我的另一個終端窗口(包含python smptd的窗口)中,運行腳本后顯示了此信息:
---------- MESSAGE FOLLOWS ----------
From: From Person <from@fromdomain.com>
To: To Person <brt381@gmail.com>
Subject: SMTP e-mail test
X-Peer: ::1
This is a test e-mail message.
------------ END MESSAGE ------------
但是...沒有電子郵件被發送。 知道有什么問題嗎? 這很好用-電子郵件已發送:
/usr/sbin/sendmail brt381@gmail.com <<<"hello"
您實際上是通過本地開發smtp服務器發送(在第一個示例中)您的電子郵件,因為您提到了DebuggingServer
類,正如文檔所述 :
創建一個新的調試服務器。 參數根據SMTPServer。 消息將被丟棄,並在標准輸出上打印。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.