Ubuntu Server 14.04 配置郵件服務傳送郵件
阿新 • • 發佈:2020-10-08
Ubuntu 中sendmail 的安裝、配置與傳送郵件的具體實現
1.安裝軟體包
sudo apt-get install sendmail sendmail-cf
2.檢視是否開啟服務
ps aux | grep sendmail
3.配置/etc/mail/sendmail.mc
cp sendmail.cf sendmail.cf.bak m4 sendmail.mc > sendmail.cf
使用mail服務還需要安裝 mailutils ,sharutils,否則無法啟用mail命令,提示未安裝該命令。
但是此時使用mail傳送郵件有如下錯誤:/var/mail/mail.err
My unqualified host name (XXX) unknown
解決方法參考文章:Sendmail: "unqualified hostname unknown; sleeping for retry unqualified hostname
在/etc/hosts 檔案中將
127.0.0.1 localhost
改為
127.0.0.1 localhost.localdomain localhost myhostname
然後傳送郵件成功:
常用傳送郵件方式如下:
1.如何寫一般的郵件:mail [email protected] Cc 編輯抄送物件,Subject:郵件主題,輸入回車,郵件正文後,按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]
PS:環境是自建的內部域名,可以向外部發送郵件但從外部向內則不能傳送郵件,因為域名為私有,公網上找不到。
轉載於:https://blog.51cto.com/xjhznick/1405533