[英]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.