1,安裝 postfix
sudo apt-get install postfix
安裝postfix,配置界面出來後選擇Internet Site,System mail name填寫 名稱
2,安裝一個 mailx 用於測試
sudo apt-get install mailx
err
sudo: unable to resolve host iZwz9aig3cb8oqsp6dy3gvZ
Reading package lists... Done
Building dependency tree
Reading state information... Done
Package mailx is a virtual package provided by:
s-nail 14.8.6-1
mailutils 1:2.99.99-1ubuntu2
bsd-mailx 8.1.2-0.20160123cvs-2
You should explicitly select one to install.
E: Package 'mailx' has no installation candidate
選擇第二項來安裝,即heirloom-mailx:
sudo apt-get install heirloom-mailx
安裝好之後,測試 發送郵件
echo "test"|mail [email protected]
喔喔,出現問題:
postdrop: warning: unable to look up public/pickup: No such file or directory
報錯原因:
與Debian Linux VPS 6,你可能得到Sendmail MTA違約。如果你已經安裝和配置後綴這可能導致錯誤。
如果您執行“echo|mail your.com”在本地配置(your.com)你會看到下面的錯誤出現:
postdrop:warning: unable to look up public/pickup: No such file or directory
解決辦法:
關閉sendmail(如果有)然後開啓postfix即可!
/etc/init.d/sendmail stop
/etc/init.d/postfix start
ps aux|grep postfix
當然,還有一個很重要的點,就是配置mailx (Ubuntu中 etc/s-nail.rc //其他系統中可能叫nail.rc 或 mail.rc)
vim /etc/s-nail.rc
set [email protected] //發信人郵箱
set smtp=smtps://smtp.qq.com:465 //發信人郵箱的SMTP地址
set smtp-auth-user=USER //發信人郵箱登陸賬號
set smtp-auth-password=PASSWORD //發信人郵箱系統提供的授權碼
set smtp-auth=login
echo"郵件內容" | mail -vs "郵件標題" [email protected]
測試成功,可以收到。
現在發送附件:
echo "This is the message body" | mail -s "subject" [email protected] -a /xx/xx/xx