使用sendmail發郵件

一、構造郵件頭和內容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/

 至此,郵件發送成功。

相關文章
相關標籤/搜索