在 Linux 中用 sendmail 代替 mail

紅寶鐵軌客
Join to follow...
Follow/Unfollow Writer: 紅寶鐵軌客
By following, you’ll receive notifications when this author publishes new articles.
Don't wait! Sign up to follow this writer.
WriterShelf is a privacy-oriented writing platform. Unleash the power of your voice. It's free!
Sign up. Join WriterShelf now! Already a member. Login to WriterShelf.
寫程式中、折磨中、享受中 ......
1.44K   0  
·
2018/06/24
·
1 mins read


現在很多 Linux 版本中都沒有內建 mail 這個 MTA(Mail transfer agent,郵件傳送代理) 了,但是 mail 用起來真的很方便啊,最好用的就是像這樣簡單的一行指令,就可以送出很棒有標題內文的郵件:

echo "Message Body" | mail -s "Message Subject" receiver@example.com

多簡單方便啊,但是因為沒有內建,所以又要多裝一個"mailutils",很討厭呀,多個香爐多個鬼,再說,如果就只要簡單的送個 command line email,有必要那麼麻煩嗎?其實可以用 sendmail,大多數的 Linux 其實都有內建 sendmail,只是 sendmail 的指令跟 mail 有點不同,其實也很簡單,用熟了就好,就以上面這個運用來說,改成以下的 command,一樣跑得很好,一樣簡單就可以送出很棒有標題內文的郵件:

echo -e "Subject:Message Subject\n\nMessage Body" | sendmail receiver@example.com

如果要送出$PATH 變數,也很簡單:

echo -e "Subject:System Path\n\n$PATH" | sendmail receiver@example.com

很奇怪的事,網路上好像大家都還是用 mail,習慣難改啊!


WriterShelf™ is a unique multiple pen name blogging and forum platform. Protect relationships and your privacy. Take your writing in new directions. ** Join WriterShelf**
WriterShelf™ is an open writing platform. The views, information and opinions in this article are those of the author.


Article info

Categories:
Tags:
Total: 267 words


Share this article:
About the Author

很久以前就是個「寫程式的」,其實,什麼程式都不熟⋯⋯
就,這會一點點,那會一點點⋯⋯




Join the discussion now!
Don't wait! Sign up to join the discussion.
WriterShelf is a privacy-oriented writing platform. Unleash the power of your voice. It's free!
Sign up. Join WriterShelf now! Already a member. Login to WriterShelf.