使用awk命令以html表格式发送邮件

问题描述:

我正尝试使用awk命令以html表格式发送邮件,如下所示:

I am trying to send mail in html table format using awk command as below:

(

echo "From: "

echo "Subject: testing of html table using awk"

awk 'BEGIN{print "<table>"} {print "<tr>";for(i=1;i<=NF;i++)print "<td>" $i"</td>";print  "</tr>"} END{print "</table>"}' file.tmp

) | sendmail xxx@yy.com

我的文件(file.tmp)包含以下内容:

And my file(file.tmp) contains as below:

AAA 1 1 1 1 0 0

SAP 1 1 1 1 0 0

RTTC 1 1 1 1 0 0

PGW 1 1 1 1 0 0

但是我收到的不是HTML表格格式的邮件,而是HTML代码本身.

But I am not getting the mail in html tabular format but instead with html code itself.

AWK命令正确吗?还是我错过了什么?

Is the AWK command correct? Or am I missing something ?

您需要添加Content-type标头:

(
    echo "From: "
    echo "Subject: testing of html table using awk"
    echo "Content-type: text/html"
    echo
    awk 'BEGIN{print "<table>"} {print "<tr>";for(i=1;i<=NF;i++)print "<td>" $i"</td>";print  "</tr>"} END{print "</table>"}' file.tmp
) | sendmail xxx@yy.com