title: Bash Script using mailx to mail attachment
body: <p>I have a bash script that runs a query in postgres, it outputs to csv.  I want to add to that script to use mailx to email that .csv file to a particular email.  </p>
  
  <p>The problem I am having is it will not email the file.  I can get the email so I know mailx is setup correctly.  I just cannot get it to email it as an attachment. It can also email the output in the body of the email.</p>
  
  <p>So here is the code.</p>
  
  <pre><code>    #!/bin/bash
      NOWDATE=`date +%m-%d-%Y`
      PGPASSWORD=password psql -w -h host -p 5432 -d database -U user -o /tmp/folder/file-$NOWDATE.csv &lt;&lt;EOF
      Query is here
  
      # remove the first 2 lines of the report as they are headers
      sed -i '2d' /tmp/folder/file-$NOWDATE.csv
  
      uuencode /tmp/folder/file-$NOWDATE.csv | mailx -s "Accounts No Credit Card Report for '$NOWDATE'" mail@gmail.com
  </code></pre>
  
  <p>I have tried the mailx part with:</p>
  
  <pre><code>    uuencode /tmp/folder/file-$NOWDATE.csv /tmp/folder/file-$NOWDATE.csv | mailx -s "Accounts No Credit Card Report for '$NOWDATE'" mail@gmail.com
  </code></pre>
  
  <p>and </p>
  
  <pre><code>    uuencode /tmp/folder/file-$NOWDATE.csv file-$NOWDATE.csv | mailx -s "Accounts No Credit Card Report for '$NOWDATE'" mail@gmail.com
  </code></pre>
  
  <p>So the problem I get is it spits out this error when I run the .sh file.</p>
  
  <pre><code>    uuencode: fopen-ing /tmp/folder/file-01-11-2011.csv: Unknown system error
  </code></pre>