2011-04-20 13 views
0

在下面的代碼中,系統發送的郵件將進入用戶的垃圾郵件文件夾,python代碼如下。我懷疑發件人是以root @身份運行的。 如何糾正這種python程序中的sendmail

def sendmail(to,fr,subject,msg): 
    sendmail_location = "/usr/sbin/sendmail" # sendmail location 
    p = os.popen("%s -t" % sendmail_location, "w") 
    p.write("From: %s\n" % fr) 
    p.write("Reply-to: %s\n" % fr) 
    p.write("To: %s\n" % to) 
    p.write("Content-type: text/html\n") 
    p.write("Subject: %s\n" % subject) 
    p.write("\n") # blank line separating headers from body 
    p.write(msg) 
    status = p.close() 

The mail format received in the

 Delivered-To: [email protected]@gmail.com 
    Received: by 19.143.162.8 with SMTP id k6gm828f7tfe; 
      Tue, 19 Apr 2011 22:42:17 -0700 (PDT) 
    Received: by 10.68.9.168 with SMTP id a5try030f516pbb.481.1303278137028; 
      Tue, 19 Apr 2011 22:42:17 -0700 (PDT) 
    Return-Path: <[email protected]> 
    Received: from ([174.1.161.204]) 
      by mx.google.com with ESMTPS id v4si18etrt0pbr.108.2011.04.19.22.42.15 
      (version=TLSv1/SSLv3 cipher=OTHER); 
      Tue, 19 Apr 2011 22:42:15 -0700 (PDT) 
    Received-SPF: neutral (google.com: 74.3.161.204 is neither permitted nor denied by best guess record for domain of [email protected]) client-ip=74.3.161.204; 
    Authentication-Results: mx.google.com; spf=neutral (google.com: 174.1.161.204 is neither permitted nor denied by best guess record for domain of [email protected]) [email protected] 
    Received: (qmail 23122 invoked by uid 0); 19 Apr 2011 22:36:27 -0000 
    Date: 19 Apr 2011 22:36:27 -0000 
    Message-ID: <[email protected]> 
    From: [email protected] 
    Subject: hi 
+0

[Sendmail without password authentication(Python 2.4)]可能的重複](http://stackoverflow.com/questions/5726781/sendmail-without-password-authentication-python-2-4) – 2011-04-20 10:10:42

回答

3

爲什麼你直接使用sendmail程序???

Python有通過任意郵件服務器 發送郵件一個很好的的smtplib模塊和用於撰寫適當的RFC-822兼容郵件的電子郵件模塊

不太可能推薦你正在做的事情。

+0

email.mime不可用在Python 2.4? – Rajeev 2011-04-20 07:02:06

+0

檢查你自己:http://docs.python.org/release/2.4.4/lib/module-email.html – 2011-04-20 07:29:23