sendEmail 是一個郵件代理傳輸程序,當sendmail程序得到一封待發送的郵件的時候,它需要根據目標地址確定將信件投遞給對應的服務器,這是通過DNS服務實現的。例如一封郵件的目標地址是[email protected],那麼sendmail首先確定這個地址是用戶名(yangql)+機器名(163.com)的格式,然後,通過查詢DNS來確定需要把信件投遞給某個服務器。
工作時遇到要定時獲取服務器上的一個文件,所以就想到了sendEmail。下面介紹一下sendEmail的配置和使用:
一 獲取sendEmail的安裝包:
[root@localhost ~]#wget http://caspian.dotconf.net/menu/Software/SendEmail/sendEmail-v1.56.tar.gz
--20:35:50-- http://caspian.dotconf.net/menu/Software/SendEmail/sendEmail-v1.56.tar.gz
正在解析主機 caspian.dotconf.net... 69.164.196.234
Connecting to caspian.dotconf.net|69.164.196.234|:80... 已連接。
已發出 HTTP 請求,正在等待迴應... 200 OK
長度:29740 (29K) [application/x-gzip]
Saving to: `sendEmail-v1.56.tar.gz'
100%[=================================================>] 29,740 62.8K/s in 0.5s
20:35:52 (62.8 KB/s) - `sendEmail-v1.56.tar.gz' saved [29740/29740]
二 解壓並進入解壓的文件
[root@localhost ~]#tar -zxvf sendEmail-v1.56.tar.gz
sendEmail-v1.56/
sendEmail-v1.56/CHANGELOG
sendEmail-v1.56/README
sendEmail-v1.56/README-BR.txt
sendEmail-v1.56/TODO
sendEmail-v1.56/sendEmail
sendEmail-v1.56/sendEmail.pl
[root@localhost ~]#cd sendEmail-v1.56
[root@localhost sendEmail-v1.56]# ls
CHANGELOG README README-BR.txt sendEmail sendEmail.pl TODO
四 將sendEmail 文件拷貝到/usr/local/bin 目錄下,並賦與其可執行權限
[root@localhost sendEmail-v1.56]#cp sendEmail /usr/local/bin
[root@localhost sendEmail-v1.56]#chmod +x /usr/local/bin/sendEmail
[root@localhost sendEmail-v1.56]# cd ~
==修改root用戶的路徑PATH變量,使其包含sendEmail(此步驟可選)
[root@localhost ~]#vim .bash_profile
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/bin:/usr/local/bin
export PATH
unset USERNAME
".bash_profile" 13L, 206C 已寫入
sendEmail的常用參數:
-m:郵件的內容,如果不帶此參數,會提示用戶手工輸入
-f:郵件發送者
-s:STMP服務器的域名或者IP地址
-u:郵件的主題
-t:郵件接收者,如果需要發送多個,使用","隔開郵件人地址即可
-xu:表示SMTP驗證的用戶名
-xp:SMTP驗證的密碼
-o:文本信息字符集,若無 -o參數,發送的含有中文時會有亂碼問題!
測試:
[root@localhost ~]#sendEmail -u "`whoami`@`hostname`: test" \
> -m "`whoami`@`hostname`:test" \
> -f [email protected] -s 10.18.100.3:25 -t [email protected]
Aug 01 20:43:29 localhost sendEmail[4325]:Email was sent successfully!
問題1:
[root@java bin]#/usr/bin/sendemail -o tls=yes -s "smtp.exmail.qq.com:465" -f "發送郵箱" -t "接收郵箱" -xu "發送郵箱" -xp "發送郵箱密碼" -u "郵件標題" -m "郵件正文"
返回:ERROR => Timeout while reading from smtp.exmail.qq.com:465 There was no response after 60 seconds.
解決方法:將465換成587,即爲/usr/bin/sendemail -o tls=yes -s "smtp.exmail.qq.com:587" -f "發送郵箱" -t "接收郵箱" -xu "發送郵箱" -xp "發送郵箱密碼" -u "郵件標題" -m "郵件正文"
問題2:
[root@java bin]#/usr/bin/sendemail -o tls=yes -s "smtp.exmail.qq.com:587" -f "發送郵箱" -t "接收郵箱" -xu "發送郵箱" -xp "發送郵箱密碼" -u "郵件標題" -m "郵件正文"
返回:invalid SSL_version specified at /usr/share/perl5/vendor_perl/IO/Socket/SSL.pm line 444.
解決方法:vi /usr/bin/sendemail
第 1906 行,將 'SSLv3 TLSv1' 修改爲 'SSLv23:!SSLv2'