一、安裝sendmail與mail
1、安裝sendmail:
1) centos下可以安裝命令:yum -y install sendmail
2) 安裝完后啟動sendmail命令:service sendmail start
2、安裝mail
安裝命令:yum install -y mailx
1、通過文件內容發送
發送命令:mail -s 'mail test' xxx@yyy.com < con.txt ("mail test"為郵件主題,xxx@yyy.com為收件人郵箱,con.txt保存郵件內容)
2、通過管道符直接發送
發送命令:echo "this is my test mail" | mail -s 'mail test' xxx@yyy.com
上述發送郵件默認會使用linux當前登錄用戶信,通常會被當成垃圾郵件,指定發件人郵箱信息命令:vi /etc/mail.rc,編輯內容如:
set from=username@163.com
set smtp=smtp.163.com
set smtp-auth-user=username@163.com
set smtp-auth-password=smtp授權碼
set smtp-auth=login
注意配置中的smtp-auth-password不是郵箱登錄密碼,是郵箱服務器開啟smtp的授權碼,每個郵箱開啟授權碼操作不同(網易163郵箱開啟菜單:設置-> 客戶端授權密碼)。
報錯:
My unqualified host name (xxx) unknown; sleeping for retry
因為sendmail在解析hostname時出現問題,修改/etc/hosts,添加127.0.0.1 xxx.xxx.com xxx
opendaemonsocket: daemon MTA: cannot bind: Address already in use
查看postfix服務是否啟動,停掉它;或mail.rc新增配置不對
參考博文:https://www.cnblogs.com/hanganglin/p/6510216.html