linux腳本實現(xiàn)自動發(fā)送和收取郵件的設置方法
更新時間:2013年05月11日 19:51:45 作者:
這篇文章主要是介紹linux下通過腳本自動發(fā)送和收取郵件的設置方法,有需要的朋友可以參考下
1. 命令行模式下的發(fā)送郵件
1.1 安裝sendemail
2.2 使用sendemail和舉例
2. 命令行模式下的收取郵件
2.1 安裝getmail4
2.2 配置getmail4和簡單舉例
2.3 用munpack從郵件中抽取附件
1. 命令行模式下的發(fā)送郵件
1.1 安裝sendemail
在Ubuntu下可以用新立得軟件包管理器搜索安裝,或者在終端運行:
sudo apt-get install sendemail
建議在安裝前先安裝另外兩個包:libio-socket-ssl-perl, libnet-ssleay-perl
2.2 使用sendemail和舉例
如果你想用你的郵箱christ@gmail.com發(fā)送郵件到buddha@qq.com,在終端輸入:
sendemail -s smtp.gmail.com -f christ@gmail.com -t buddha@qq.com -u hello -m "A hello from Christans to buddhists via gmail" -xu christ -xp password -o tls=auto
解釋:
-s smtp.gmail.com 指定服務器域名,郵件發(fā)送一般通過SMTP協(xié)議實現(xiàn),其域名一般為smtp.***.com,比如qq郵箱的服務器為smtp.qq.com,163郵箱則為smtp.163.com
-f christ@gmail.com指定發(fā)送郵箱地址
-t buddha@qq.com 指定目的郵箱地址
-u hello 郵件標題
-m "A hello from Christans to buddhists via gmail" 郵件正文,較長的正文可以先存在文本文件中,不妨命名為mail.txt,然后換用-o message-file=mail.txt
-xu christ 指定郵箱用戶名,即郵箱地址@之前的部分
-xp password 指定發(fā)送郵箱的密碼
-o tls=auto 加密方式在none, tls, ssl中自動選擇
如果想在郵件中粘帖附件
-a attachment_file1 attachment_file2 attachment_file3
2. 命令行模式下的收取郵件
通過郵件客戶端收取email郵件主要有兩種方式:POP3和IMAP,郵件客戶端通過POP3下載服務器上的郵件,但是IMAP默認只下載郵件的主題。基于命令行方式自動化的意義,采用POP3更合適。
2.1 安裝getmail4
在Ubuntu下可以用新立得軟件包管理器搜索安裝,或者
sudo apt-get install getmail4
2.2 配置getmail4和簡單舉例
安裝完畢后在終端執(zhí)行一下命令
cd ~
mkdir .getmail
cd .getmail
mkdir maildir
cd maildir
mkdir new cur tmp
后在 .getmail/下建立一個配置文件,如果這個配置文件是為收取buddha@qq.com這個郵箱配置的,不妨命名為getmailrc.buddha,然后編輯該文件,#后是注釋:
# This is a configuration file for buddha@qq.com
[retriever]
type = SimplePOP3Retriever
server = pop.qq.com #如果是gmail則改為pop.gmail.com
username = budda
password = password
[destination]
type = Maildir
path = ~/.getmail/maildir/ #就是剛才在~/.getmail/建立的目錄,注意該目錄下一定要有new,cur,tmp這三個子目錄
[options]
read_all = False #只接受以前沒有收取的郵件,如果改成True則收取郵箱中所有郵件
delete = False #下載郵件后不在服務器上刪除該郵件,如果改成True則刪除
# configuration file ends here
編輯好了之后在終端運行:
getmail --rcfile=getmailrc.buddha
getmail會自動收取郵件,下載的郵件會保存在~/.getmail/maildir/new/下。
2.3 用munpack從郵件中抽取附件
郵件正文和附件是作為一個整體文件被保存的,附件以MIME格式附著在整體文件最后,必須用程序抽取出來。
在Ubuntu下可以用新立得軟件包管理器搜索安裝mpack,或者 sudo apt-get install mpack
在終端中運行:munpack mail_file
程序會自動識別附件并抽取出來。
1.1 安裝sendemail
2.2 使用sendemail和舉例
2. 命令行模式下的收取郵件
2.1 安裝getmail4
2.2 配置getmail4和簡單舉例
2.3 用munpack從郵件中抽取附件
1. 命令行模式下的發(fā)送郵件
1.1 安裝sendemail
在Ubuntu下可以用新立得軟件包管理器搜索安裝,或者在終端運行:
sudo apt-get install sendemail
建議在安裝前先安裝另外兩個包:libio-socket-ssl-perl, libnet-ssleay-perl
2.2 使用sendemail和舉例
如果你想用你的郵箱christ@gmail.com發(fā)送郵件到buddha@qq.com,在終端輸入:
sendemail -s smtp.gmail.com -f christ@gmail.com -t buddha@qq.com -u hello -m "A hello from Christans to buddhists via gmail" -xu christ -xp password -o tls=auto
解釋:
-s smtp.gmail.com 指定服務器域名,郵件發(fā)送一般通過SMTP協(xié)議實現(xiàn),其域名一般為smtp.***.com,比如qq郵箱的服務器為smtp.qq.com,163郵箱則為smtp.163.com
-f christ@gmail.com指定發(fā)送郵箱地址
-t buddha@qq.com 指定目的郵箱地址
-u hello 郵件標題
-m "A hello from Christans to buddhists via gmail" 郵件正文,較長的正文可以先存在文本文件中,不妨命名為mail.txt,然后換用-o message-file=mail.txt
-xu christ 指定郵箱用戶名,即郵箱地址@之前的部分
-xp password 指定發(fā)送郵箱的密碼
-o tls=auto 加密方式在none, tls, ssl中自動選擇
如果想在郵件中粘帖附件
-a attachment_file1 attachment_file2 attachment_file3
2. 命令行模式下的收取郵件
通過郵件客戶端收取email郵件主要有兩種方式:POP3和IMAP,郵件客戶端通過POP3下載服務器上的郵件,但是IMAP默認只下載郵件的主題。基于命令行方式自動化的意義,采用POP3更合適。
2.1 安裝getmail4
在Ubuntu下可以用新立得軟件包管理器搜索安裝,或者
sudo apt-get install getmail4
2.2 配置getmail4和簡單舉例
安裝完畢后在終端執(zhí)行一下命令
復制代碼 代碼如下:
cd ~
mkdir .getmail
cd .getmail
mkdir maildir
cd maildir
mkdir new cur tmp
后在 .getmail/下建立一個配置文件,如果這個配置文件是為收取buddha@qq.com這個郵箱配置的,不妨命名為getmailrc.buddha,然后編輯該文件,#后是注釋:
復制代碼 代碼如下:
# This is a configuration file for buddha@qq.com
[retriever]
type = SimplePOP3Retriever
server = pop.qq.com #如果是gmail則改為pop.gmail.com
username = budda
password = password
[destination]
type = Maildir
path = ~/.getmail/maildir/ #就是剛才在~/.getmail/建立的目錄,注意該目錄下一定要有new,cur,tmp這三個子目錄
[options]
read_all = False #只接受以前沒有收取的郵件,如果改成True則收取郵箱中所有郵件
delete = False #下載郵件后不在服務器上刪除該郵件,如果改成True則刪除
# configuration file ends here
編輯好了之后在終端運行:
getmail --rcfile=getmailrc.buddha
getmail會自動收取郵件,下載的郵件會保存在~/.getmail/maildir/new/下。
2.3 用munpack從郵件中抽取附件
郵件正文和附件是作為一個整體文件被保存的,附件以MIME格式附著在整體文件最后,必須用程序抽取出來。
在Ubuntu下可以用新立得軟件包管理器搜索安裝mpack,或者 sudo apt-get install mpack
在終端中運行:munpack mail_file
程序會自動識別附件并抽取出來。
相關文章
linux dev 常見特殊設備介紹與應用(loop,null,zero,full,random)
這篇文章主要介紹了linux dev 常見特殊設備介紹與應用(loop,null,zero,full,random),需要的朋友可以參考下2015-10-10putty實現(xiàn)自動登錄的方法(ssh和ssh2)
這篇文章主要介紹putty實現(xiàn)自動登錄的方法,需要的朋友可以參考下2013-02-02利用shell腳本遍歷文件夾內所有的文件并作整理統(tǒng)計的方法
今天小編就為大家分享一篇利用shell腳本遍歷文件夾內所有的文件并作整理統(tǒng)計的方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-06-06