sendEmail是Linux下優秀的第三方郵件命令,非常簡單,可以設置 smtp,不會被認定為SPAM(垃圾郵件)或直接拒收。
本文原文轉自米撲博客:CentOS 6/7 配置 sendEmail 發送郵件
sendEmail 官網:http://caspian.dotconf.net/menu/Software/SendEmail/
sendEmail 下載:sendEmail-v1.56.tar.gz (2009)
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 robot@mimvp.com -t yanggang@mimvp.com -s smtp.exmail.qq.com -u "郵件標題" -o message-charset=utf-8 -xu robot@mimvp.com -xp mimvp-password -m "郵件正文內容"
結果錯誤,信息如下:
# /usr/local/bin/sendEmail -f robot@mimvp.com -t yanggang@mimvp.com -s smtp.exmail.qq.com -u "郵件標題" -o message-charset=utf-8 -xu robot@mimvp.com -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 robot@mimvp.com -t yanggang@mimvp.com -s smtp.exmail.qq.com -u "郵件標題" -o message-charset=utf-8 -xu robot@mimvp.com -xp mimvp-password -m "郵件正文內容" -o tls=no
# /usr/local/bin/sendEmail -f robot@mimvp.com -t yanggang@mimvp.com -s smtp.exmail.qq.com -u "郵件標題" -o message-charset=utf-8 -xu robot@mimvp.com -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 yanggang@163.com -t yanggang@mimvp.com -s smtp.163.com -u "郵件標題" -o message-charset=utf-8 -xu yanggang@163.com -xp mimvp-auth-code -m "郵件正文內容" -o tls=no
# /usr/local/bin/sendEmail -f yanggang@163.com -t yanggang@mimvp.com -s smtp.163.com -u "郵件標題" -o message-charset=utf-8 -xu yanggang@163.com -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 發送郵件,結果沒有成功!
感興趣的您,可以繼續折騰下,搞定的歡迎留言告訴我哈 ~.~
參考推薦:
Centos7 配置 sendmail、postfix 端口號25、465