首先,卸载掉系统自带的sendmail和postfix:
yum remove sendmail
yum remove postfix

然后在/etc/mail.rc中添加下面几行:
set from=123456@126.com
set smtp=smtp.126.com  
set smtp-auth-user=123456
set smtp-auth-password=xxxxxxx
set smtp-auth=login
说明:from是指发件人,smtp-auth-user和smtp-auth-password是指用户名和密码,smtp-auth配置为登录方式。

接下来就是使用mail命令来发邮件了,执行下面的命令:
echo "Content Hello" | mail -s "Test Title" -a testfile.txt 123456@qq.com
说明:echo的内容为邮件正文,-s是指邮件标题,-a是指附件,最后的123456@qq.com是指收件人。
更多用法请参考mail的man手册。