参考:http://www.4wei.cn/archives/1001468
参考:http://blog.csdn.net/wave_1102/article/details/46463849
------------------ 我是分割线 ------------------------
说明:
linux自带的mail可以实现外部smtp发邮件。不需要本地配置postfix,sendmail邮件服务器,配置整套下来确实需要点时间。
实现:
1.关闭本机的sendmail服务或者postfix服务
点击(此处)折叠或打开
-
sendmail
-
# service sendmail stop
-
# chkconfig sendmail off
-
-
postfix
-
# service postfix stop
- # chkconfig postfix off
2.修改/etc/mail.rc,增加一下类似N行,指定外部的smtp服务器地址、帐号密码等。
点击(此处)折叠或打开
-
# cp /etc/mail.rc /etc/mailrc.bak.20131113
-
# cat /etc/mail.rc //内容如下
-
set from=123456@qq.com
-
set smtp=smtp.qq.com
-
set smtp-auth-user=123456
-
set smtp-auth-password=sbsbsbsb
- set smtp-auth=login
3.然后通过命令来发送邮件
点击(此处)折叠或打开
- # echo hello word | mail -s " title" 123456@qq.com
- # mail -v -s "title" 123456@qq.com < 附件.zip 添加附件的方式发送邮件
RHEL6下发送邮件没有问题。但RHEL5下,一直没办法发送。这是为什么呢?可以先看下RHEL6和RHEL5下mail和mailx的不同
RHEL6下
点击(此处)折叠或打开
-
# rpm -qa|grep mailx
-
mailx-12.4-6.el6.x86_64
-
# ll /bin/mail* //mail链接到mailx,mailx版本为12.4
-
lrwxrwxrwx. 1 root root 5 7月 22 2011 /bin/mail -> mailx
-
-rwxr-xr-x. 1 root root 390424 2月 16 2010 /bin/mailx
-
# mail -V
- 12.4 7/29/08
RHEL5下,则发现了一些不同
点击(此处)折叠或打开
-
# rpm -qa|grep mailx
-
mailx-8.1.1-44.2.2
-
# ll /bin/mail* //mailx链接到mail命令,mailx版本为8.1
-
-rwxr-xr-x 1 root mail 84856 Jun 6 2007 /bin/mail
-
lrwxrwxrwx 1 root root 4 Apr 12 18:03 /bin/mailx -> mail
- # mail -V 此处运行就会出错,没有-V这个参数
1.RHEL5安装新版本mailx
点击(此处)折叠或打开
-
# wget ftp://ftp.spline.inf.fu-berlin.de/pub/gentoo/distfiles/mailx-12.4.tar.bz2 //下载mailx-12.4.tar.bz2,更多下载地址http://www.filewatcher.com/m/mailx-12.4.tar.bz2.271482.0.0.html
-
# tar jxvf mailx-12.4.tar.bz2
-
# cd mailx-12.4
-
# make
-
# make install UCBINSTALL=/usr/bin/install
-
# whereis mailx //查看mailx程序默认安装位置、及版本
-
mailx: /usr/local/bin/mailx /usr/share/man/man1p/mailx.1p.gz
-
# mailx -V
- 12.4 7/29/08
2.修改/etc/nail.rc,安装后的mailx使用的是/etc/nail.rc而不是/etc/mail.rc。这个需要注意下!!!
点击(此处)折叠或打开
-
# vi /etc/nail.rc //在行尾添加如下行
-
set from=123456@qq.com
-
set smtp=smtp.qq.com
-
set smtp-auth-user=123456
-
set smtp-auth-password=sbsbsbsb
- set smtp-auth=login
3.然后通过命令来发送邮件
点击(此处)折叠或打开
-
# echo hello word | mailx -v -s " title" 123456@qq.com //成功发送的话,就可以看到类似的提示
-
235 2.7.0 Authentication successful
-
>>> MAIL FROM:<demo@qq.com>
-
250 2.1.0 Ok
-
>>> RCPT TO:<xxxxx@qq.com>
-
250 2.1.5 Ok
-
>>> DATA
-
354 End data with <cr><lf>.<cr><lf>
-
>>> .
-
250 2.0.0 Ok: queued as 9291963494
-
>>> QUIT
- 221 2.0.0 Bye
亲测163邮箱可以正常使用,qq邮箱需要设置SSL。