Как отправить письмо в виде HTML из скрипта bash с помощью команды mail или mailx (Centos / Redhat) - PullRequest
0 голосов
/ 12 апреля 2019

Я пытаюсь отправить электронное письмо из скрипта bash, в котором должна быть HTML-таблица, Я использую почтовую команду в Redhat. но его продолжают посылать мне как текстовый файл.

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

Спасибо

1 Ответ

0 голосов
/ 12 апреля 2019

Попробуйте по почте (не забудьте добавить свои переменные):

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

Если вам нужно отправить из CentOS / RedHat по mailx, используйте его:

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>
...
...