(1)linux
直接使用shell當編輯器
shell
# mail -s "Hello from linuxde.net by shell" admin@linuxde.net hello,this is the content of mail. welcome to www.linuxde.net
第一行是輸入的命令,-s表示郵件的主題,後面的admin@linuxde.net則是郵件的接收人,輸入完這行命令後回車,會進入郵件正文的編寫,咱們能夠輸入任何文字,好比上面的兩行。當郵件正文輸入完成後,須要按CTRL+D結束輸入,此時會提示你輸入Cc地址,即郵件抄送地址,沒有直接回車就完成了郵件的發送。
使用管道進行郵件發送編輯器
echo "hello,this is the content of mail.welcome to www.linuxde.net" | mail -s "Hello from linuxde.net by pipe" admin@linuxde.net this
使用管道直接敲入這行命令便可完成郵件的發送,其中echo後的是郵件正文。 spa
使用文件進行郵件發送 .net
mail -s "Hello from linuxde.net by file" admin@linuxde.net < mail.txt code
使用上面的命令後,咱們就能夠把mail.txt文件的內容做爲郵件的內容發送給admin@linuxde.net了。 blog
使用上述三種方式均可以給外部郵箱進行郵件發送,但由於前面2中都是直接在shell中敲入郵件內容,所以沒法輸入中文,即便咱們使用粘貼的方式輸入了中文,那麼收到的郵件也是亂碼的。但第3種方式,咱們能夠在window下編輯好郵件內容後,放到linux下,再進行發送,這樣就能夠正常發送中文了。不過目前郵件的中文標題暫時沒有找到解決辦法。ip
由於mail程序自己就是調用sendmail來進行郵件發送的,所以咱們能夠在mail命令中使用sendmail的參數進行配置,好比我想使用特定的發件人發送郵件,能夠使用以下命令:get
mail -s "Hello from linuxde.net with sender" admin@linuxde.net -- -f user@linuxde.net < mail.txt
使用-- -f user@linuxde.net,能指定郵件的發件人是 「user@linuxde.net」。
上面的命令中,咱們使用了–- -f user@linuxde.net這樣的參數,這是sendmail的選項,其中-f表示郵件的發送人郵件地址。
來自: http://man.linuxde.net/mail