【问题标题】:How to send a html file using mails in shell script?如何使用 shell 脚本中的邮件发送 html 文件?
【发布时间】:2017-07-28 06:30:56
【问题描述】:

我想将矩阵的数据存储在 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"

我希望我的输出是一个对齐良好的表格。有人可以帮我吗? TIA

【问题讨论】:

  • 这个的输出是什么? mailx -a 'Content-Type: html' -s "my subject" tapariak@amazon.com &lt; output.html
  • 我的脚本名称是 parseScript.sh,所以当我运行这个脚本时,我运行如下: ./parseScript.sh > output.html ,这样我的输出应该存储在 output.html 中,然后我我正在使用邮件发送该文件
  • 我不明白你在说什么你的邮件是内容类型text 将它更改为html 你在使用mailUtils 吗?
  • 在哪里更改邮件的内容类型?
  • 试试我的答案,让我知道

标签: html bash shell outlook mailx


【解决方案1】:

您需要在标题中附加内容类型,可以使用mailx 中的-a 标志来完成

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

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

编辑:

根据 OP End 错误: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/

【讨论】:

  • 它给了我这个错误:Content-Type: text/html: No such file or directory
  • 您对content-type 使用了单一代码吗?就像答案一样?
  • 你是如何安装mailx的?
  • 当我从公司拿到这台 Mac 时,它已经在那里了。这个问题的可能原因是什么?
  • 我在我的linux机器上试过imgur.com/86de9Fn请在命令行中尝试答案,让我知道你是否得到同样的错误
【解决方案2】:

也许你可以用这个做基础:

( 回声“收件人:地址” 回声“主题:主题” echo "内容类型:文本/html" 回声 回显“HTML代码” ) | /usr/sbin/sendmail -F "NameOfSender" -t

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-07-06
    • 2010-12-21
    • 1970-01-01
    • 2010-12-19
    • 2014-10-13
    • 1970-01-01
    • 2016-11-22
    • 1970-01-01
    相关资源
    最近更新 更多