Rajeev
Rajeev

Reputation: 46899

sendmail from python program

In the below code ,the mails that are going from the system are going to a spam folder for the user ,the python code is given below.I suspect that sender from is going as root@. How to correct this

  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: harry@[email protected]
     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: [email protected]
     Subject: hi

Upvotes: 1

Views: 756

Answers (1)

user2665694
user2665694

Reputation:

Why do you use the sendmail binary directly???

Python has a nice smtplib module for sending mail through arbitrary mail servers and an email module for composing proper RFC-822 compliant mails.

What you are doing is unlikely recommended.

Upvotes: 3

Related Questions