Linux bash mail发邮件总结

需要sendmail或postfix服务

如果单纯的发文件文件可以用
cat xxxx.txt |mail -s "主旨" [email protected] [email protected]

如果需要发送附件需要安装uuencode来编码 (yum install sharutils)

单独发附件,这样[email protected]会收到一个data.txt的附件
uuencode /tmp/data_process.log data.txt |mail [email protected]

如果需要正文和附件一起发:
uuencode /tmp/data_process.log data.txt > /tmp/data_temp.txt
上面是将编码的文件输出:

cat /tmp/data_temp.txt /tmp/data_process.log > /tmp/data_ok.txt
上面是将编码文件和内容合并

cat /tmp/data_ok.txt |mail -s "主旨" [email protected] [email protected]
上面是发送


发送HTML邮件:

#!/usr/bin/ksh

export MAILTO="[email protected]"
export CONTENT="/tmp/example.html"
export SUBJECT="Example Report"
(
echo "Subject: $SUBJECT"
echo "MIME-Version: 1.0"
echo "Content-Type: text/html"
echo "Content-Disposition: inline"
cat $CONTENT
) | /usr/sbin/sendmail $MAILTO

你可能感兴趣的:(linux)