unix - Send html table with csv attachment using mail command -


i have csv file want attach. have created html table of csv aswell inline display of table below. if not attach file, script runs fine.

cat htmltempfile  <head>  <style> table {     border-collapse: collapse;     width: 70%; }  th, td {     padding: 8px;     text-align: left;     border-bottom: 1px solid #ddd; }  tr:hover{background-color:#dddddd} </style> </head> <body> <table> <tr><th>team</th><th>type</th><th>10:15:00</th><th>11:15:00</th><th>12:15:00</th><th>13:15:00</th><th>14:15:00</th><th>15:15:00</th><th>15:30:00</th></tr> <tr><td>c</td><td>w</td><td>278645</td><td>434543</td><td>4906</td><td>55494</td><td>68232</td><td>7341</td><td>123641</td></tr> <tr><td>b</td><td>p</td><td>63361</td><td>79405</td><td>75303</td><td>7243</td><td>74224</td><td>7331</td><td>26159</td></tr> <tr><td>b</td><td>w</td><td>28357</td><td>97934</td><td>1000</td><td>20005</td><td>16875</td><td>2004</td><td>0</td></tr> <tr><td></td></tr> </table>  today=$(date +%y%m%d | tr -d '\n') emaillist="a@b.com appname="path/to/csv/file.csv" htmltempfile="path/to/csv/htmltempfile" cat "$htmltempfile" | mail -s "$(echo -e "subject:$today $appname.\ncontent-type: text/html")"  $emaillist #runs fine   cat "$htmltempfile" | mail -s "$(echo -e "subject:$today $appname.\ncontent-type: text/html")" -a $appname $emaillist #problem  

the same file being attached not attached properly

i see in gmail

the mail -a won't work attachments. have use "uuencode" attaching files.

if want show html summary , attachment use below.

sendemail() {    boundary=$(date +%s|md5sum)   boundary=${boundary:0:32}    filename=$(basename $appname)   (     echo "from: x@b.com";     echo "to: $emaillist";     echo "reply-to: x@b.com";     echo "subject: $today $appname.";     echo "content-type: multipart/mixed; boundary=\"$boundary\"";     echo "";     echo "this mime formatted message.  if see text means your";     echo "email software not support mime formatted messages, plain text";     echo "encoded should ok, plain text file.";     echo "";     echo "--$boundary";     echo "content-type: text/html; charset=iso-8859-1; format=flowed"     echo "content-transfer-encoding: 8bit"     echo "content-disposition: inline";     echo ""     cat "$htmltempfile";     echo "";     echo "--$boundary";     echo "content-type: text/plain; name=\"$filename\"";     echo "content-transfer-encoding: 8bit";     echo "content-disposition: attachment; filename=\"$filename\";"     echo ""     cat "$appname";     echo "";     echo "--$boundary--";   )  | /usr/sbin/sendmail -t 2>/dev/null }   today=$(date +%y%m%d | tr -d '\n') emaillist="a@b.com appname="path/to/csv/file.csv" htmltempfile="htmltempfile" sendemail 

Comments

Popular posts from this blog

html - How to set bootstrap input responsive width? -

javascript - Highchart x and y axes data from json -

javascript - Get js console.log as python variable in QWebView pyqt -