- Ubuntu下使用最常用的mail功能,需要安裝mailutils,安裝命令:sudo apt-get install mailutils
- 使用帶附件的功能,則還需要安裝sharutils,安裝命令:sudo apt-get install sharutils;yum install sharutils
- redhat下需要啓動sendmail服務:/etc/init.d/sendmail start
打開終端,輸入命令:
sudo apt-get install sendmail 安裝完 ps aux |grep sendmail 輸出如下: root 9391 0.0 0.3 8748 2000 ? Ss 00:14 0:00 sendmail: MTA: accepting connections andy 13332 0.0 0.1 3236 792 pts/0 R+ 03:58 0:00 grep sendmail 證明sendmail已經成功啓動了 sudo vi /etc/php5/apache2/php.ini 找到 sendmail_path,修改爲: sendmail_path = /usr/sbin/sendmail -i -t 重啓apache sudo apache2ctl restart |
測試
常用發送郵件方式如下:
1.如何寫一般的郵件: mail flynewton@gmail 編輯抄送對象,郵件主題,郵件正文後,按Ctrl-D結束
2.快速發送方式: echo “郵件正文” | mail -s 郵件主題 [email protected]
3.以文件內容作爲郵件正文來發送: mail -s test [email protected] < test.txt
4.發送帶附件的郵件: uuencode 附件名稱 附件顯示名稱 | mail -s 郵件主題 發送地址
例如: uuencode test.txt test.txt | mail -s Test [email protected]
----------------------------------------
在ubuntu下搭建sendmail 後,使用上述命令,測試成功,第三條在英文環境下,也可以正常發送中文內容的txt文檔,並在外部收件箱裏正常顯示
環境是自建的內部域名,可以向外部發送郵件
但從外部向內則不能發送郵件,因爲域名爲私有,公網上找不到