如果没有mail命令,使用yum安装:
[plain]view plaincopy#yuminstall-ymailx
要发送html格式邮件,关键是在邮件头部指定内容格式,如下:
[plain]view plaincopy$mail-s"$(echo-e"subject\nContent-Type:text/html;charset=utf-8")"receiver@<mail.htm
这里最巧妙的是使用了echo -e,使得subject输入了一个回车,就可以在头部定义Content-Type了。
sendmail发送html邮件倒是比较简单,只要把发送的头部和内容都定义到一个文件中,然后读取文件发送就可以了,文件内容如下:
mail.htm:
[plain]view plaincopyFrom:sender<sender@> To:receiver<receiver@> Subject:subject Content-Type:text/html;charset=utf-8 <html> <body> content </body> </html> .
发送邮件时:
[plain]view plaincopy$sendmail-t<mail.htm