在下面的代码中,来自系统的邮件将进入用户的垃圾邮件文件夹,下面给出了 python 代码。我怀疑发件人来自 root@。 如何纠正这个问题
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()
接收到的邮件格式
Delivered-To: harry@8767@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: <root@.>
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 root@.) 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 root@.) smtp.mail=root@.
Received: (qmail 23122 invoked by uid 0); 19 Apr 2011 22:36:27 -0000
Date: 19 Apr 2011 22:36:27 -0000
Message-ID: <2010041954235627.25121.qmail@>
From: admin@xxxxxx.com
Subject: hi
最佳答案
为什么直接使用sendmail二进制文件???
Python 有一个很好的 smtplib 模块,用于通过任意邮件服务器发送邮件 和一个电子邮件模块,用于编写符合 RFC-822 规范的邮件。
不太可能推荐您正在做的事情。
关于python - 从 python 程序发送邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5726391/