2014-10-09 238 views
0

我下面的python腳本蟒蛇SMTP電子郵件不工作

import sys 
from smtplib import SMTP    
from email.mime.text import MIMEText 
class EmailSender(): 

    def send_email(self, msg_text): 
    SMTPserver = ‘localhost' 
    conn = SMTP(SMTPserver)  

    try: 
     sender =  ‘[email protected]' 
     destination = '[email protected]' 
     text_subtype = 'plain' 
     msg = MIMEText(msg_text, text_subtype) 
     msg['Subject']= "subject" 
     msg['From'] = sender 
     msg['To'] = destination 

     conn.sendmail(sender, [destination], msg.as_string()) 
    except Exception, exc: 
     sys.exit("mail failed; %s" % str(exc)) # give a error message 
    finally: 
     conn.close() 

腳本運行正常沒有報告任何錯誤,但我沒有看到任何郵件。 後綴正在運行

sudo postfix start 
netstat -an | grep 'LISTEN'| grep 25 
tcp4  0  0 127.0.0.1.25   *.*     LISTEN 

請發現我的錯誤。我打電話通過

email_sender = EmailSender() 
email_sender.send_email("SOMETHING BROKE!") 
+0

您是否檢查垃圾郵件文件夾? – Beginner 2014-10-09 16:29:05

+0

如何檢查/ var/mail下的垃圾郵件? – kk1957 2014-10-09 16:34:32

+0

本地計算機上的Postfix配置是否正確?你能證明通過讓其他電子郵件客戶端通過它發送郵件嗎? – 2014-10-09 16:34:54

回答

0

好吧,這是交易。我在上面的腳本中將目標編輯爲一個gmail帳戶,並且它像一個魅力一樣工作。那麼問題是什麼? '[email protected]'目標基本上由Microsoft電子郵件服務器支持。我試圖通過發送電子郵件

echo "testing mail" | mailx -s "this is a test email from `hostname`" [email protected] 

並看到它最後在/ var/email /交付失敗報告如下:

最終收件人:rfc822; [email protected] 操作失敗 狀態:5.7.1 Remote-MTA:dns; .... protection.outlook.com Diagnostic-Code:smtp;暫停服務;使用FBLW15阻止客戶端主機 ;要請求從此列表中刪除 請將此消息轉發給[email protected]

因此,微軟阻止了電子郵件從我的計算機發出。