一、构造邮件头和内容html
To: xx@xx.com
Cc:
From: xx@xx.com
Subject: xxxx
Content-type:text/html;charset=utf-8编码
<head></head>spa
<body>code
邮件内容htm
</body>utf-8
</html>get
二、发送邮件字符编码
cat mail_content | /usr/sbin/sendmail xxx@xxx.combase64
三、邮件内容格式乱码
若是要发送html格式的邮件, 就是说,邮件的消息体为一个html文件,须要在邮件头中指定 content-type为 text/html。若是不指定,默认状况下,content-type为text/plain,即普通文本,字符编码设置为utf-8。
四、邮件标题乱码问题
用sendmail发邮件时,很容易出现标题乱码的状况,这时能够使用以下方法解决:
=?UTF-8?B?”+base64encode(用utf-8编码的中文内容)+"?=
例如:
Subject : =?UTF-8?B?5L2g5aW9?=
其中红色部分为采用base64encode编码后的中文“你好”,在线base64encode编码网址:http://www.base64encode.org/
至此,邮件发送成功。