title: Python 2.7 subprocess module: Sending email with date in subject line
body: <p>I am trying to automate a report, the last part of which is mailing the report to recipients. The standard procedure is to have the date of the report in the email subject line. The underlying system is a CentOS machine. See the code I have below:</p>
  
  <pre><code>import subprocess
  
  emailto = "email@address.com"
  filenm = "report-parked-domains.csv"
  
  subprocess.Popen("/bin/mailx -a %s -s 'cPanel Parked Domains Report for `date +%%Y-%%m`' %s &lt; emailbody.txt" % (filenm, emailto), shell = True)
  </code></pre>
  
  <p>When the email is sent, the recipient receives an email formatted the following way:</p>
  
  <pre><code>cPanel Parked Domains Report for `date +%Y-%m`
  </code></pre>
  
  <p>I am not sure how to escape the Linux year and month variables from the string that is the email subject.</p>
  
  <p>Any help with how I could fix this? I thought of using the 'datetime' module, but 1. don't know how to implement that in the subprocess command I am using and 2. don't want to get another Undeliverable message sent to my manager. :)</p>
  
  <p>Thanks!</p>