[英]How to sent Email as HTML from bash script by using mail or mailx command (Centos/Redhat)
我試圖從bash腳本發送一封電子郵件,該電子郵件應該包含HTML表格,我在Redhat中使用mail命令。 但它不斷發送我作為文本文件。
difference=`expr $artu_removed - $artu_added`
mail -s "Built notification" test@gmail.com << EOF
<html>
<head><title></title>
</head>
<body>
<table>
<tr>
<Td> Before </td> <td>after </td> <td>differece </td>
</tr>
<tr>
<Td> $_before </td> <td>$_after </td> <td>$difference </td>
</tr>
</table>
Before:$_before
After:$_after
Difference:$difference
</body>
</html>
EOF
任何人都可以讓我知道我該怎么做,我使用的是Redhat,而不是ubuntu
謝謝
通過郵件嘗試(不要忘記添加變量):
mail -a "Content-type: text/html" -s "HTML message" test@gmail.com << EOF
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Title</title>
</head>
<body>
<table>
<tr>
<td> Before </td>
<td> After </td>
<td> Differece </td>
</tr><tr>
<td> $_before </td>
<td> $_after </td>
<td> $difference </td>
</tr>
</table>
Before: $_before
After: $_after
Difference: $difference
</body>
</html>
EOF
如果您需要通過mailx從CentOS / RedHat發送,請使用它:
mail -s "$(echo -e "HTML message\nContent-Type: text/html")" test@gmail.com << EOF
嘗試前景:
mail -s "$(echo -e "HTML message\nContent-Transfer-Encoding: 7bit\nUser-Agent: Heirloom mailx 12.4 7/29/08\nMIME-Version: 1.0\nContent-Type: text/html; charset=us-ascii\nContent-Transfer-Encoding: 7bit")" test@outlook.com << EOF
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<title>Title</title>
...
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.