![表格电子邮件格式以及附件](https://linux22.com/image/166697/%E8%A1%A8%E6%A0%BC%E7%94%B5%E5%AD%90%E9%82%AE%E4%BB%B6%E6%A0%BC%E5%BC%8F%E4%BB%A5%E5%8F%8A%E9%99%84%E4%BB%B6.png)
我有一个在路径中生成的客户文件。我想以表格格式发送该文件中的数据以及作为电子邮件附件的文件。我有一个示例脚本,我从中得到了帮助,下面是我得到的:
#initialising variables
dt=`date +%Y%m%d`;
[email protected]
TO="[email protected]";
CC=""
BCC=""
SUBJECT="Manager Accounts KPI Results - $dt";
BOUNDARY="PARAEND";
set -x
File_path="/File_gen/data"
script_path="/File_gen/data"
Mail_Content="$File_path/Customer_KPI_Mail.ml"
Mail_Opener()
{
echo "From: "$FROM"
To: "$TO"
cc: "$CC"
bcc: "$BCC"
Subject: "$SUBJECT"
Mime-Version: 1.0
Content-Type: multipart/alternative; boundary=\"$BOUNDARY\"
--$BOUNDARY
Content-Type: text/html
<html>
<style>
table{
border-collapse:collapse;
}
caption{
margin:0;
padding:0;
#border:1px solid black;
}
th{
background-color:#BAFFBA;
}
</style>
<body>
<span id='notification'> <i> << This is an automated notification. please do not respond to this email.>> </i> </span> <br /> <br />
<div>
Hi All - <br /> <br />
Please find the results $dt .<br /> <br />
<table border=1 cellpadding=3>
<tr>
<th> Rule_Name </th>
<th> Lower_Variance </th>
<th> Upper_Variance </th>
<th> Current_Day_Variance </th>
<th> Result_Check </th>
</tr>
" > $Mail_Content
}
Mail_Closure()
{
echo "</table><br /> <br />
</div>
<div>Thanks, <br />
Global Team </div>
</body>
</html>" >> $Mail_Content
}
Table_Content_Designer()
{
col1="$1";
col2="$2";
col3="$3";
col4="$4";
col5="$5";
echo "<td> $col1 </td>" >> $Mail_Content
echo "<td> $col2 </td>" >> $Mail_Content
echo "<td> $col3 </td>" >> $Mail_Content
echo "<td> $col4 </td>" >> $Mail_Content
echo "<td> $col5 </td>" >> $Mail_Content
}
Mail_Opener;
cat "$script_path/cust_acct_check.txt" |sed 1d | while read line
do
line="$File_path"/"$line";
counter=1;
line_count=`wc -l $line | awk -F " " '{print $1}'`;
cat $line | while read data
do
col1=`echo $data | awk -F "," '{print $1}'`;
col2=`echo $data | awk -F "," '{print $2}'`;
col3=`echo $data | awk -F "," '{print $3}'`;
col4=`echo $data | awk -F "," '{print $4}'`;
col5=`echo $data | awk -F "," '{print $5}'`;
if [ $counter -gt 1 ]; then
if [ $counter -eq $line_count ];then
Table_Content_Designer "$col1" "$col2" "$col3" "$col4" "$col5";
echo "</tr>" >> $Mail_Content
counter=`expr $counter + 1`;
fi
if [ $counter -lt $line_count ];then
Table_Content_Designer "$col1" "$col2" "$col3" "$col4" "$col5";
echo "</tr>" >> $Mail_Content
echo "<tr>" >> $Mail_Content
counter=`expr $counter + 1`;
fi
else
counter=`expr $counter + 1`;
fi
done
done
Threshold_File="$File_path/cust_acct_check.txt"
if [ -s "$Threshold_File" ];then
echo "</table><br /> <br />
</div>
<div>The data file is alos located at Target path <br />
Please reach out to the GDMART <[email protected]> in case of any questions. <br /> <br /></div>
<div>Thanks, <br />
Global Team </div>
</body>
</html>
--$BOUNDARY
Content-Type: application;name="cust_acct_check.txt"
Content-Transfer-Encoding: base32
Content-Disposition: attachment; filename="cust_acct_check.txt"
" >> $Mail_Content
cat "$Threshold_File" >> $Mail_Content
else
Mail_Closure;
fi
cat "$Mail_Content" | sendmail -t
下面是我想要放入表格格式的 csv 文件:
#key_rule,Lower_variance,Upper_variance,Actual_value,Result_check
MGR_ACCT_CNT,0,9000,8,True
MGR_BAL_CHK,-0.035,0.035,0.063997,False
MGR_ACCT_COM,-1,1,1.170281,False