简体   繁体   English

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

[英]How to send a html file using mails in shell script?

I want to store my matrix's data in a html file and send a email in outlook ,my code looks as follows: 我想将矩阵的数据存储在html文件中,并在Outlook中发送电子邮件,我的代码如下所示:

  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" test@example.com < output.html
  mailx -s "TESTING MAIL"</home/test/example/output.html  "test@example.com"

I want my output as a well aligned table. 我希望将输出作为一个对齐的表。 Can someone help me on this? 有人可以帮我吗? TIA TIA

You need to append content-type in header it can be done with -a flag in mailx 您需要在标头中附加content-type,这可以通过mailx -a标志完成

comment your last line and try this 评论您的最后一行,然后尝试

mailx -a 'Content-Type: text/html' -s "Test MAIL" test@example.com</home/test/example/output.html

Edit : 编辑:

As per the OP End error : content-type:texthtml no such file or directory 根据OP End错误: content-type:texthtml no such file or directory

To install mailutils in mac 在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

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

Maybe you can use this for a base: 也许您可以以此为基础:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM