从Linux服务器发送电子邮件为html - 电子邮件中也可以看到内容类型和html标签

问题描述 投票:0回答:2

我正在尝试以html格式发送电子邮件。

#!/bin/sh

#MAIL_LIST="[email protected]"
MAIL_SENDER=foo

fnSendEmail(){
    echo ${BODY}| mail -r $MAIL_SENDER -s "$(echo "$MAIL_SUBJECT\nContent-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 email\nContent-Type: text/html"

电子邮件正文:

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

先感谢您

html linux shell email
2个回答
0
投票

使用选项-a添加内容类型标题,-s是主题,将fnSendEmail更改为以下它应该工作

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

0
投票

我使用sendmail完成了它

#MAIL_LIST1="[email protected]"
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
© www.soinside.com 2019 - 2024. All rights reserved.