如何使用shell脚本中的邮件发送html文件?

问题描述:

我要存储在一个HTML文件我矩阵的数据,并在Outlook中发送电子邮件,我的代码如下:如何使用shell脚本中的邮件发送html文件?

printf "<!DOCTYPE html>" 
    printf "<html>" 
    printf "<head>" 
    printf "<style>" 

    printf "</style>" 
    printf "</head>" 
    printf "<body>" 

    printf "<table>" 
    printf "<tr>" 
    printf "<th>Total</th>" 
     printf "<th>StillFail</th>" 
     printf "<th>Pass</th>" 
     printf "<th>ScriptError</th>" 
     printf "<th>APIName</th>" 
    printf "</tr>" 
    printf "<tr>" 
    echo 
     for ((j=1;j<=num_rows;j++)) do 
     printf "<tr>" 
     for ((i=1;i<=num_columns;i++)) do 
       printf "<td>" 
       printf "${matrix[$j,$i]}" 
       printf "</td>" 
     printf "</tr>" 
     done 
    echo 
    done 
    printf "</tr>" 
    printf "</table>" 

    printf "</body>" 
    printf "</html>" 
    #mailx -a 'Content-Type: html' -s "my subject" [email protected] < output.html 
    mailx -s "TESTING MAIL"</home/tapariak/keshav/output.html "[email protected]" 

出来把对应于该代码如下:outlook email

我想我的输出是一个很好对齐的表格。有人可以帮助我吗? TIA

+0

什么的输出呢? 'mailx -a'Content-Type:html'-s“我的主题”[email protected]

+0

我的脚本名是parseScript.sh,所以当我运行这个脚本时,我运行如下:./parseScript .sh> output.html,这样我的输出应该存储在output.html中,然后我使用邮件邮寄那个文件 –

+0

我不明白你在说什么你的邮件是content-type'text'把它改为'html '你在用'mailUtils'吗? –

您需要添加内容类型的头可与-a标志来完成在mailx

评论你的最后一行,并尝试这个

mailx -a 'Content-Type: text/html' -s "Test MAIL" [email protected]</home/tapariak/keshav/output.html 

编辑:

根据OP结束错误:content-type:texthtml no such file or directory

在Mac上安装mailutils

Press Command+Space and type Terminal and press enter/return key. 
Run in Terminal app: 
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" < /dev/null 2> /dev/null 
and press enter/return key. Wait for the command to finish. 
Run: 
brew install mailutils 

参考:http://macappstore.org/mailutils/

+0

它给了我这个错误:Content-Type:text/html:没有这样的文件或目录 –

+0

你使用单一代码的'content-type'吗?因为它在答案中? –

+0

是的,我做到了。我在回答中使用了完全相同的命令 –

也许你可以用这个基地:

 
    (
echo "To: ADRESSES" 
echo "Subject: SUBJECT" 
echo "Content-Type: text/html" 
echo 
echo "HTML code" 
) | /usr/sbin/sendmail -F "NameOfSender" -t