How to send HTML File in a e-mail Body unis Mailx or mail command

梦想的初衷 提交于 2020-04-18 05:48:18

问题


Is there a way to send html file into a mail body using mail or mailx command in Linux. I googled around and did not find anything that's working though there are many threads. on of the thread i see Mailx send html message but nothing works.

What i used are below commands but not working as expected.

$ mail -s "$(echo -e "This is Subject\nContent-Type: text/html")"  kulfi@tap.com <  OneView_Sheet.html

$ mailx -s "$(echo -e "This is Subject\nContent-Type: text/html")"  kulfi@tap.com <  OneView_Sheet.html

The above command instead sending the html source content as follows ...

<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>OV_NAME</th>
      <th>Composer_Firmware</th>
      <th>SAS_20_Firmware_Version</th>
      <th>SAS12_Firmware_Version</th>
      <th>VC_Firmware_Version</th>
    </tr>
  </thead>
  <tbody>

Desired example as on the Body:


回答1:


Trying with your dummy HTML table did worked with mutt. Below command can help you to get your email notifications sorted.

mutt -e "set content_type=text/html" -e "set from=sender@tap.com" -s "This is Subject" kulfi@tap.com < OneView_Sheet.html

Another common mechanism which can be preferred in case of mail & mailx failures is sendmail -t

echo To: kulfi@tap.com >mailheader.txt
echo This is Subject >>mailheader.txt
echo Content-Type: text/html >>mailheader.txt
cat OneView_Sheet.html >> mailheader.txt
cat mailheader.txt| sendmail -t

Since both mutt and sendmail are supported most of the standard flavours which are in general use, you may not need to add any additional libraries / tools.



来源:https://stackoverflow.com/questions/61014131/how-to-send-html-file-in-a-e-mail-body-unis-mailx-or-mail-command

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!