CentOS CLI命令行mailx发送邮件基本用法

Share on:

mailx安装,很简单!貌似我的系统自带的。

yum remove mailx #卸载系统自带的旧版mailx

编译安装mailx:
http://nchc.dl.sourceforge.net/project/heirloom/heirloom-mailx/12.4/mailx-12.4.tar.bz2
tar jxvf mailx-12.4.tar.bz2 #解压
cd mailx-12.4 #进入目录
make #编译
make install UCBINSTALL=/usr/bin/install #安装
ln -s /usr/local/bin/mailx /bin/mail #创建mailx到mail的软连接
ln -s /etc/nail.rc /etc/mail.rc #创建mailx配置文件软连接

我先介绍下系统的版本和mailx的版本

12.4 7/29/08
[root@localhost ~]# cat /etc/issue
CentOS release 6.8 (Final)
Kernel \r on an \m

mailx的配置文件在/etc/mail.rc
在配置文件中添加下面的代码(passwd写开通smtp客户端给的授权码)

set smtp=smtp.qq.com
set smtp-auth-user=111******53@qq.com
set smtp-auth-password=euia********chb   #授权码
set smtp-auth=login

直接报错了(没有使用ssl的节奏)

smtp-server: 530 Error: A secure connection is requiered(such as ssl). More information at http://service.mail.qq.com/cgi-bin/help?id=28
"/root/dead.letter" 19/438
. . . message not sent

改成

set smtp=smtp.qq.com
set smtp-auth-user=111******53@qq.com
set smtp-auth-password=euia********chb   #授权码
set smtp-auth=login
set smtp-use-starttls
set ssl-verify=ignore
set nss-config-dir=/root/.certs

又报错Error in certificate: Peer’s certificate issuer is not recognized.

证书问题,解决方法

echo -n | openssl s_client -connect smtp.qq.com:465 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > ~/.certs/qq.crt
certutil -A -n "GeoTrust SSL CA" -t "C,," -d ~/.certs -i ~/.certs/qq.crt
certutil -A -n "GeoTrust Global CA" -t "C,," -d ~/.certs -i ~/.certs/qq.crt
certutil -L -d /root/.certs
certutil -A -n "GeoTrust SSL CA - G3" -t "Pu,Pu,Pu"  -d ./ -i qq.crt

有些邮箱无法通过上述方式获取证书,我们可以在装有火狐浏览器的服务器中把证书拷贝过来

一些常用的命令

mailq

#邮件队列的文件都保存在 /var/spool/mqueue/ 文件夹内,查看此文件夹时,可以看到邮件队列内的邮件:
[root@CHINFO3 mqueue]# pwd
/var/spool/mqueue
[root@CHINFO3 mqueue]# ls
dftB111d4Q031164  dftB213omV012806  dftB36BqUi005128  qftB117J4b006323  qftB21TicN013397
dftB117J4b006323  dftB21TicN013397  qftB111d4Q031164  qftB213omV012806  qftB36BqUi005128

#如果需要删除队列,直接清空该文件夹即可:
[root@CHINFO3 mqueue]# rm -f *
[root@CHINFO3 mqueue]# ls
[root@CHINFO3 mqueue]# mailq
/var/spool/mqueue is empty
        Total requests: 0
[root@CHINFO3 mqueue]#

参考
http://irow10.blog.51cto.com/2425361/1812638

闽ICP备12003472号-7