使用 sendmail 不显示收件人地址

Using sendmail do not show recipient address

我正在尝试检查 Linux 中的 server status,因此如果不是 运行,我想发送一封电子邮件,这很容易做到,而我' m 创建一个 HTML 正文以通过 outlook 发送电子邮件,同时在 cron 中进行设置。

显然一切正常,但唯一的问题是我在查看 outlook 时看不到 ToCC 邮件地址。

下面是一个小片段。

STATUS="$(systemctl is-active smb.service)"
if [ "${STATUS}" = "active" ]; then
    echo "SAMBA Server is running fine"
else
   export MAILTO="some_email@example.com"
   export CC="other_email@example.com"
   export SUBJECT="Critical:: SAMBA Service Status $(hostname)"
   export FROM="Mailman@nxp.com"
   export EMAIL_TEMPLATE="""\
          <html>
            <head>
            <style>
            table, th, td {{font-size:9pt; border:1px solid black; border-collapse:collapse; text-align:left; background-color:LightGray;}} th, td {{padding: 5px;}}
            </style>
            </head>
            <body>
              Dear Team,<br><br>
              SAMBA Service is not running on <strong>$(hostname)</strong> which is Critical for business hence look into it and Fix it Urgently!<br><br>
              You may check the status of the service like: <strong>systemctl status smb.service</strong> , Please take further steps as required!
              <br><br>
              <br><br>
              Kind regards.<br>
              Support Mailman.
            </body>
          </html>"""
   (
    echo "Subject: $SUBJECT"
    echo "From: $FROM"
    echo "MIME-Version: 1.0"
    echo "Content-Type: text/html"
    echo "Content-Disposition: inline"
    echo '<HTML><BODY><PRE>'
    echo $EMAIL_TEMPLATE
    echo '</PRE></BODY></HTML>'
   ) | /usr/sbin/sendmail $MAILTO $CC

    exit 1
fi

结果:

如您所见,它没有显示 To 邮件地址,如果您有任何提示,请告诉我。

您需要回显 To:CC: header,就像其他所有内容一样。地址在命令行但不在 header 中的是盲拷贝。

   (
    echo "To: $MAILTO"
    echo "Cc: $CC"
    echo "Subject: $SUBJECT"
    echo "From: $FROM"
    echo "MIME-Version: 1.0"
    echo "Content-Type: text/html"
    echo "Content-Disposition: inline"
    echo '<HTML><BODY><PRE>'
    echo $EMAIL_TEMPLATE
    echo '</PRE></BODY></HTML>'
   ) | /usr/sbin/sendmail "$MAILTO" "$CC"

如果您不想将它们作为 sendmail 的参数重复,您可以使用 -t 选项。这告诉它从 header 中获取收件人地址。