从Linux服务器中发送电子邮件为内容类型,而HTML标签也可以在电子邮件中可见



我试图将电子邮件作为html发送。

#!/bin/sh
#MAIL_LIST="gangadhar.n@xx.com"
MAIL_SENDER=foo
fnSendEmail(){
    echo ${BODY}| mail -r $MAIL_SENDER -s "$(echo "$MAIL_SUBJECTnContent-Type: text/html")" "$MAIL_LIST"
}
MAIL_SUBJECT="Test email"
BODY="<html><body><div><h2>Hi All</h2><hr></div></body></html>";
fnSendEmail $BODY $MAIL_SENDER $MAIL_SUBJECT $MAIL_LIST 

我正在接收电子邮件,但是HTML标签和内容类型也可以在下面的邮件中可见。

主题为

"Test emailnContent-Type: text/html"

电子邮件主体AS

<html><body><div><h2>Hi All</h2><hr></div></body></html> NOTICE TO RECIPIENT:  If you are not the intended recipient of this e-mail, you are prohibited from sharing, copying, or otherwise using or disclosing its contents.  If you have received this e-mail in error, please notify the sender immediately by reply e-mail and permanently delete this e-mail and any attachments without reading, forwarding or saving them.  Thank you.

预先感谢您

我已经使用sendmail

做到了
#MAIL_LIST1="Gangadhar.N@xx.com"
MAIL_SENDER=dap
fnSendEmail(){
(
  echo To: $MAIL_LIST
  echo Cc: $MAIL_LIST
  echo From: dap53
  echo "Content-Type: text/html; "
  echo Subject: $MAIL_SUBJECT
  echo
  echo $BODY
) | /usr/sbin/sendmail -t
}
MAIL_SUBJECT="Test email"
BODY="<html><body>Sample</body></html>"
fnSendEmail $BODY $MAIL_SENDER $MAIL_SUBJECT $MAIL_LIST

使用选项-a附加内容类型标头,-s为主题,将您的fnsendemail更改为遵循它应该有效

fnSendEmail(){
    echo ${BODY}| mail -r $MAIL_SENDER -a "Content-type: text/html" -s "$(echo "$MAIL_SUBJECTn")" "$MAIL_LIST"
}

最新更新