Ubuntu下使用mail命令發送郵件

  • mail命令在Ubuntu下是須要安裝的,使用下條命令進行安裝:
  •  sudo apt-get install heirloom-mailx
  • 接下來輸入用戶密碼,等待安裝完成
  • 此時還不能發送外部服務器郵件,須要完成如下配置,修改/etc/nail.rc或者/etc/s-nail.rc(Ubuntu)、/etc/mail.rc(centOS)
  • vi /etc/nail.rc或者/etc/s-nail.rc
  • 此時若是打印沒有權限則使用sudo命令
  • 在nail.rc文件末尾添加一下兩行代碼:
  • set from=郵箱地址 smtp=smtp.郵箱地址後綴 //如set from=123456@qq.com smtp=smtp.qq.com
  • set smtp-auth-user=郵箱地址 smtp-auth-password="郵箱密碼" smtp-auth=login
  • 按照以上步驟設置完畢以後便可使用mail命令發送郵件,發送郵件有如下三種方式:
  • 方法一:交互形式發送郵件
    • mail + 郵箱地址
    • 填寫主題
    • 填寫內容
    • ctrl + d 結束輸入
    • cc表明抄送,回車完成發送
  • 方法二:通道形式發送
    • echo "郵件內容" | mail -s "主題" 郵箱地址
  • 方法三:讀取文件內容發送
    • mail -s "主題" "郵箱地址" < "path/filename"  
相關文章
相關標籤/搜索