淺析linux下如何用腳本自動(dòng)發(fā)送文本mail郵件
更新時(shí)間:2013年05月12日 11:27:12 作者:
這篇文章主要是介紹如何linux下通過(guò)腳本自動(dòng)發(fā)送文本mail郵件,特分享下,方便需要的朋友
1. 安裝msmtp
luther@gliethttp:~$ sudo apt-get install msmtp
2. 編輯配置腳本(~/.msmtprc是默認(rèn)配置文件,也可以使用-C選項(xiàng)指定配置文件路徑)
luther@gliethttp:~$ vim msmtprc
#添加如下內(nèi)容
defaults
#logfile /home/luther/msmtp.log
account luther_test
host mail.gliethttp.cn
from luther@gliethttp.cn
auth off
password 123456789
account default : luther_test
3. 去掉配置文件的執(zhí)行權(quán)限-x
luther@gliethttp:~$ chmod 600 msmtprc
4. 好了,可以使用下面語(yǔ)句發(fā)送一個(gè)測(cè)試郵件到自己的郵箱了,或者在stdin上輸入,然后ctrl+D
可能文件中的部分?jǐn)?shù)據(jù)會(huì)丟失,不怕,當(dāng)我們安裝mutt之后就一切正常了.
luther@gliethttp:~$ msmtp luther@gliethttp.cn -C /home/luther/msmtprc < /vobs/tmp/log.c
5. 接著安裝mutt
luther@gliethttp:~$ sudo apt-get install mutt
6. 編輯配置腳本(~/.muttrc是默認(rèn)配置文件,也可以使用-F選項(xiàng)指定配置文件路徑)
luther@gliethttp:~$ vim muttrc
#添加如下內(nèi)容
set sendmail="/usr/bin/msmtp -C /home/luther/msmtprc"
set use_from=yes
set from=admin@gliethttp.cn
set realname="測(cè)試admin"
set editor="vim"
7. 發(fā)送普通文本和文件內(nèi)容
luther@gliethttp:~$ echo "測(cè)試123abc" | mutt -F /home/luther/muttrc -s "郵件標(biāo)題 - 測(cè)試" luther@gliethttp.cn
luther@gliethttp:~$ mutt -F /home/luther/muttrc -s "郵件標(biāo)題 - 測(cè)試" luther@gliethttp.cn < /etc/passwd
8. 發(fā)送附件(-a選項(xiàng)用來(lái)添加附件,下面這個(gè)例子添加了passwd和resolv.conf這2個(gè)附件)
luther@gliethttp:~$ echo "測(cè)試123abc" | mutt -F /home/luther/muttrc -s "郵件標(biāo)題 - 測(cè)試" luther@gliethttp.cn -a /etc/passwd -a /etc/resolv.conf
9. bcc地址和cc抄送地址發(fā)送,如果多個(gè)郵件地址,使用逗號(hào)分隔即可
luther@gliethttp:~$ echo "測(cè)試123abc" | mutt -F /home/luther/muttrc -s "
郵件標(biāo)題 - 測(cè)試" luther@gliethttp.cn,luther.ge@163.com -b luther.ge@163.com,luther@gliethttp.cn -c luther.ge@163.com,luther@gliethttp.cn
luther@gliethttp:~$ sudo apt-get install msmtp
2. 編輯配置腳本(~/.msmtprc是默認(rèn)配置文件,也可以使用-C選項(xiàng)指定配置文件路徑)
luther@gliethttp:~$ vim msmtprc
#添加如下內(nèi)容
defaults
#logfile /home/luther/msmtp.log
account luther_test
host mail.gliethttp.cn
from luther@gliethttp.cn
auth off
password 123456789
account default : luther_test
3. 去掉配置文件的執(zhí)行權(quán)限-x
luther@gliethttp:~$ chmod 600 msmtprc
4. 好了,可以使用下面語(yǔ)句發(fā)送一個(gè)測(cè)試郵件到自己的郵箱了,或者在stdin上輸入,然后ctrl+D
可能文件中的部分?jǐn)?shù)據(jù)會(huì)丟失,不怕,當(dāng)我們安裝mutt之后就一切正常了.
luther@gliethttp:~$ msmtp luther@gliethttp.cn -C /home/luther/msmtprc < /vobs/tmp/log.c
5. 接著安裝mutt
luther@gliethttp:~$ sudo apt-get install mutt
6. 編輯配置腳本(~/.muttrc是默認(rèn)配置文件,也可以使用-F選項(xiàng)指定配置文件路徑)
luther@gliethttp:~$ vim muttrc
#添加如下內(nèi)容
set sendmail="/usr/bin/msmtp -C /home/luther/msmtprc"
set use_from=yes
set from=admin@gliethttp.cn
set realname="測(cè)試admin"
set editor="vim"
7. 發(fā)送普通文本和文件內(nèi)容
luther@gliethttp:~$ echo "測(cè)試123abc" | mutt -F /home/luther/muttrc -s "郵件標(biāo)題 - 測(cè)試" luther@gliethttp.cn
luther@gliethttp:~$ mutt -F /home/luther/muttrc -s "郵件標(biāo)題 - 測(cè)試" luther@gliethttp.cn < /etc/passwd
8. 發(fā)送附件(-a選項(xiàng)用來(lái)添加附件,下面這個(gè)例子添加了passwd和resolv.conf這2個(gè)附件)
luther@gliethttp:~$ echo "測(cè)試123abc" | mutt -F /home/luther/muttrc -s "郵件標(biāo)題 - 測(cè)試" luther@gliethttp.cn -a /etc/passwd -a /etc/resolv.conf
9. bcc地址和cc抄送地址發(fā)送,如果多個(gè)郵件地址,使用逗號(hào)分隔即可
luther@gliethttp:~$ echo "測(cè)試123abc" | mutt -F /home/luther/muttrc -s "
郵件標(biāo)題 - 測(cè)試" luther@gliethttp.cn,luther.ge@163.com -b luther.ge@163.com,luther@gliethttp.cn -c luther.ge@163.com,luther@gliethttp.cn
相關(guān)文章
linux下使用ssh遠(yuǎn)程執(zhí)行命令批量導(dǎo)出數(shù)據(jù)庫(kù)到本地
這篇文章主要介紹了linux下使用ssh遠(yuǎn)程執(zhí)行命令批量導(dǎo)出數(shù)據(jù)庫(kù)到本地,需要的朋友可以參考下2015-04-04Linux SHELL if命令參數(shù)說(shuō)明
SHELL if命令參數(shù)介紹,方便學(xué)習(xí)shell命令的朋友,需要的朋友可以參考下2013-01-01shell腳本檢查域名證書(shū)是否過(guò)期的流程分析
由于域名即將過(guò)期,所以最近打算替換相關(guān)網(wǎng)站證書(shū)為最新的,主要的流程就是讀取文件中的域名,然后進(jìn)行https訪問(wèn)獲取到證書(shū)過(guò)期的時(shí)間,如果域名連接不上,則會(huì)直接跳過(guò),具體詳細(xì)過(guò)程跟隨小編一起通過(guò)本文學(xué)習(xí)下吧2022-02-02Shell字符串截取的實(shí)現(xiàn)方法(非常詳細(xì))
這篇文章主要介紹了Shell字符串截取的實(shí)現(xiàn)方法(非常詳細(xì)),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2021-03-03Shell腳本中$符號(hào)的嵌套使用方法小結(jié)
在編寫(xiě)Shell腳本時(shí),通過(guò)嵌套使用$符號(hào),間接獲取變量或表達(dá)式的值的具體方法,文中根據(jù)實(shí)例編碼詳細(xì)介紹的十分詳盡,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2023-05-05linux shell之控制臺(tái)打印各種顏色字體和背景的實(shí)現(xiàn)方法
今天小編就為大家分享一篇關(guān)于linux shell之控制臺(tái)打印各種顏色字體和背景的實(shí)現(xiàn)方法,小編覺(jué)得內(nèi)容挺不錯(cuò)的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來(lái)看看吧2019-04-04