1. 程式人生 > >CentOS 6/7 配置 sendEmail 傳送郵件

CentOS 6/7 配置 sendEmail 傳送郵件

sendEmail是Linux下優秀的第三方郵件命令,非常簡單,可以設定 smtp,不會被認定為SPAM(垃圾郵件)或直接拒收。

1、sendEmail 下載

2、解壓、安裝

tar zxvf sendEmail-v1.56.tar.gz
cd sendEmail-v1.56
cp sendEmail /usr/local/bin/

檢視解壓後的檔案

# ll sendEmail-v1.56
total 116
-rw-r--r-- 1 root root 13329 Sep 30  2009 CHANGELOG
-rw-r--r-- 1 root root  7949 Sep 30  2009 README
-rw-r--r-- 1 root root  4701 Sep 30  2009 README-BR.txt
-rwxr-xr-x 1 root root 80213 Sep 30  2009 sendEmail
lrwxrwxrwx 1 root root     9 Sep 30  2009 sendEmail.pl -> sendEmail
-rw-r--r-- 1 root root  1229 Sep 30  2009 TODO

3、sendEmail 引數

sendEmail -h

-f 表示傳送者的郵箱
-t 表示接收者的郵箱
-s 表示SMTP伺服器的域名或者ip
-u 表示郵件的主題
-xu 表示SMTP驗證的使用者名稱
-xp 表示SMTP驗證的密碼(注意,這個密碼貌似有限制,例如我用d!5neyland就不能被正確識別)
-m 表示郵件的內容
-cc 表示抄送
-bcc 表示暗抄送

4、應用例項

1)qq企業郵箱傳送郵件

/usr/local/bin/sendEmail -f [email protected]om -t [email protected] -s smtp.exmail.qq.com -u "郵件標題" -o message-charset=utf-8 -xu

[email protected] -xp mimvp-password -m "郵件正文內容"

結果錯誤,資訊如下:

# /usr/local/bin/sendEmail -f [email protected] -t [email protected] -s smtp.exmail.qq.com -u "郵件標題" -o message-charset=utf-8 -xu [email protected] -xp mimvp-password -m "郵件正文內容"
*******************************************************************
 Using the default of SSL_verify_mode of SSL_VERIFY_NONE for client
 is deprecated! Please set SSL_verify_mode to SSL_VERIFY_PEER
 together with SSL_ca_file|SSL_ca_path for verification.
 If you really don't want to verify the certificate and keep the
 connection open to Man-In-The-Middle attacks please set
 SSL_verify_mode explicitly to SSL_VERIFY_NONE in your application.
*******************************************************************
  at /usr/local/bin/sendEmail line 1906.
invalid SSL_version specified at /usr/share/perl5/vendor_perl/IO/Socket/SSL.pm line 424.

檢視原始碼:

vim /usr/share/perl5/vendor_perl/IO/Socket/SSL.pm +424

    ${*$self}{'_SSL_arguments'} = $arg_hash;
    ${*$self}{'_SSL_ctx'} = IO::Socket::SSL::SSL_Context->new($arg_hash) || return;
    ${*$self}{'_SSL_opened'} = 1 if $is_server;

應該是 perl 版本不相容

# perl -v
 
This is perl 5, version 16, subversion 3 (v5.16.3) built for x86_64-linux-thread-multi
(with 29 registered patches, see perl -V for more detail)
 
Copyright 1987-2012, Larry Wall

解決方案,sendEmail 增加兩個引數

-o tls=no    // sendEmail -h 檢視幫助,解釋是 -o tls=<auto|yes|no>         -o fqdn=FQDN  即不驗證 ssl

完整且正確命令:

/usr/local/bin/sendEmail -f [email protected] -t [email protected] -s smtp.exmail.qq.com -u "郵件標題" -o message-charset=utf-8 -xu [email protected] -xp mimvp-password -m "郵件正文內容" -o tls=no

# /usr/local/bin/sendEmail -f [email protected] -t [email protected] -s smtp.exmail.qq.com -u "郵件標題" -o message-charset=utf-8 -xu [email protected] -xp mimvp-password -m "郵件正文內容" -o tls=no
Aug 02 00:27:47 mimvp-sz sendEmail[15493]: Email was sent successfully!

qq企業郵箱是 使用者名稱 + 密碼;qq個人郵箱是使用者名稱 + 隨機碼

檢視傳送的郵件:

2)163 個人郵箱傳送郵件

同樣需要加上兩個引數 -o tls=no

/usr/local/bin/sendEmail -f [email protected] -t [email protected] -s smtp.163.com -u "郵件標題" -o message-charset=utf-8 -xu [email protected] -xp mimvp-auth-code -m "郵件正文內容" -o tls=no

# /usr/local/bin/sendEmail -f [email protected] -t [email protected] -s smtp.163.com -u "郵件標題" -o message-charset=utf-8 -xu [email protected] -xp mimvp-auth-code -m "郵件正文內容" -o tls=no
Aug 02 00:31:37 mimvp-sz sendEmail[15642]: Email was sent successfully!

163個人郵箱是 使用者名稱 + 授權碼(mimvp-auth-code),不是密碼哈,設定獲取授權碼請見米撲部落格:POP3、SMTP、IMAP 的作用和聯絡

成功傳送截圖:

小結

經過對比實測,發現阿里雲封禁了25埠號的伺服器,是無法利用 sendEmail 傳送郵件的,只有開放沒封25埠號的才可以傳送

折騰了利用 smtps://smtp.exmail.qq.com:165 傳送郵件,結果沒有成功!

感興趣的您,可以繼續折騰下,搞定的歡迎留言告訴我哈 ~.~