系統(tǒng)之家 - 系統(tǒng)光盤下載網(wǎng)站!

當前位置:系統(tǒng)之家 > 系統(tǒng)教程 > linux中mail命令

通過實例了解Linux mail命令的作用

時間:2014-12-22 17:05:43 作者:qipeng 來源:系統(tǒng)之家 1. 掃描二維碼隨時看資訊 2. 請使用手機瀏覽器訪問: https://m.xitongzhijia.net/xtjc/20141222/33142.html 手機查看 評論

  Linux下mail命令對于系統(tǒng)管理員來說比較經(jīng)常使用,是個很實用的命令,可定期寄一些備忘錄提醒系統(tǒng)用戶,下面小編就給大家詳細介紹下Linux中的mail命令吧。

 通過實例了解Linux mail命令的作用

  首先通過help參數(shù)來查看mail的所有參數(shù)如下:

  代碼如下:

  Usage: mail [-BDFintv~] [-s subject] [-a attachment ] [-c cc-addr] [-b bcc-addr]

  [-r from-addr] [-h hops] [-A account] [-R reply-addr] to-addr …

  mail [-BDeHiInNRv~] [-T name] [-A account] -f [name]

  mail [-BDeinNRv~] [-A account] [-u user]

  1、發(fā)送標題加文本內(nèi)容

  運行命令:

  代碼如下:

  mail -s “this is a title” bbmonkey62@163.com

  回車,繼續(xù)輸入文本,也就是郵件內(nèi)容

  代碼如下:

  this is content

  然后按Ctrl+D退出。

  代碼如下:

  EOT

  上面是最簡單的例子,假如我們想要發(fā)送給多個郵箱呢?在上面的郵箱后面加另外的郵箱地址,郵箱間以空格隔開即可,如下:

  代碼如下:

  mail -s “this is a title” bbmonkey62@163.com admin@163.com

  在上面的例子中,發(fā)件人是Linux當前的登錄用戶名,比如我當前登錄的用戶名為admin,那么發(fā)送的郵箱地址是admin@163.com,如果郵箱后綴域名是163.com的話。但有時我們想寫上發(fā)件人的名稱,還有不想采用默認的郵箱地址,這時我們可以這么做:

  代碼如下:

  mail -s “this is a title” -r “myname@zihou.me” bbmonkey62@163.com

  這時發(fā)件人郵箱就變?yōu)榱?myname@zihou.me,一些垃圾郵件就是采用的這種方法,隱藏自己真實的郵件地址。

  如果我們想要收件人回復郵件時,回復的郵箱地址與我們的發(fā)信郵箱不同,那么我們可以自定義回復郵箱地址,如下:

  代碼如下:

  mail -s “this is a title” -r “myname@zihou.me” -R “myreply@zihou.me” bbmonkey62@163.com

  那么收信人回復時,會默認發(fā)送到myreply@zihou.me,而不是默認的myname@zihou.me。

  2、發(fā)送附件

  有時我們需要發(fā)送附件,那么也是非常容易的,如下:

  代碼如下:

  mail -s “this is a title” -r “myname@zihou.me” -a “/home/hadoop/report/3.txt” bbmonkey62@163.com

  在這里要說明一下的時,如果我們的附件是不大的文本文件,我們有時也用不著發(fā)送附件,可以直接將附件的文本當做郵件內(nèi)容發(fā)送,這樣通過郵件查看時也更方便些,如下:

  代碼如下:

  mail -s “this is a test” bbmonkey62@163.com 《 /home/hadoop/project/3.txt

  3、不用回車輸入郵件內(nèi)容發(fā)送郵件

  在上面的例子中,你如果照做的話,你會發(fā)現(xiàn)很不方便,那就是每次輸入郵件內(nèi)容都需要在命令運行后回車輸入內(nèi)容,最后還要再按Ctrl+D完成。實際上,可以不用這么費勁的,如下:

  代碼如下:

  echo “this is content” | mail -s “this is a title” bbmonkey62@163.com

  通過echo命令來輸入郵件內(nèi)容“this is content”,這樣就簡單多了!

  4、查看郵件

  通過mail命令也可以查看收到的郵件,這個我就簡單說一下吧,畢竟這個相對不常用,命令很簡單,直接輸入mail,會出現(xiàn)收到的郵件,每個郵件都對應(yīng)一個序列號,如果要查看某封郵件,直接在?后輸入數(shù)字序列號即可。

  在?后輸入help可以查看所有的參數(shù),如下:

  代碼如下:

 ? help

  mail commands

  type 《message list》 type messages

  next goto and type next message

  from 《message list》 give head lines of messages

  headers print out active message headers

  delete 《message list》 delete messages

  undelete 《message list》 undelete messages

  save 《message list》 folder append messages to folder and mark as saved

  copy 《message list》 folder append messages to folder without marking them

  write 《message list》 file append message texts to file, save attachments

  preserve 《message list》 keep incoming messages in mailbox even if saved

  Reply 《message list》 reply to message senders

  reply 《message list》 reply to message senders and all recipients

  mail addresses mail to specific recipients

  file folder change to another folder

  quit quit and apply changes to folder

  xit quit and discard changes made to folder

  ! shell escape

  cd 《directory》 chdir to directory or home if none given

  list list names of all available commands《/p》 《p》A 《message list》 consists of integers, ranges of same, or other criteria

  separated by spaces. If omitted, mail uses the last message typed.

  在?后也可以直接輸入mail寫信哦,就跟上面的例子一樣,所不同的是,每步都會有提示,如下:

  代碼如下:

 ? mail

  To: bbmonkey62@163.com

  Subject: this is a title

  content

  EOT

  上面就是Linux中mail命令的用法介紹了,其實mail命令的用法還有很多,本文只是介紹了一些主要的用法,mail還可作為一個電子郵件程式,不過使用的人比較少。

發(fā)表評論

0

沒有更多評論了

評論就這些咯,讓大家也知道你的獨特見解

立即評論

以上留言僅代表用戶個人觀點,不代表系統(tǒng)之家立場

其他版本軟件

熱門教程

人氣教程排行

Linux系統(tǒng)推薦

官方交流群 軟件收錄